@things-factory/integration-base 7.0.1-rc.8 → 7.0.1

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.
@@ -89,12 +89,19 @@ class ConnectionManager {
89
89
  return connection;
90
90
  }
91
91
  static getConnectionInstanceEntityByName(domain, name) {
92
- const entities = ConnectionManager.entities[domain.id];
93
- return entities === null || entities === void 0 ? void 0 : entities[name];
92
+ var _a, _b;
93
+ const connection = (_a = ConnectionManager.entities[domain.id]) === null || _a === void 0 ? void 0 : _a[name];
94
+ if (connection) {
95
+ return connection;
96
+ }
97
+ if (domain.parentId) {
98
+ return (_b = ConnectionManager.entities[domain.id]) === null || _b === void 0 ? void 0 : _b[name];
99
+ }
94
100
  }
95
101
  static getConnectionInstances(domain) {
96
102
  const connections = ConnectionManager.connections[domain.id];
97
- return Object.assign({}, connections);
103
+ const parentConnections = domain.parentId && ConnectionManager.connections[domain.parentId];
104
+ return Object.assign(Object.assign({}, parentConnections), connections);
98
105
  }
99
106
  static getConnectionInstanceEntities(domain) {
100
107
  const connections = ConnectionManager.entities[domain.id];
@@ -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,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,C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AAE,EAAE,EAAE;IACzE,OAAO,GAAG,SAAS,IAAI,KAAK,KAAK,KAAK,IAAI,OAAO,EAAE,CAAA;AACrD,CAAC,CAAC,CAAA;AAEY,wBAAM,GAAG,IAAA,sBAAY,EAAC;IAClC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,iBAAiB,CAAC,SAAS,CAAC;IAClH,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, 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"]}
1
+ {"version":3,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AAW,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, 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 connection = ConnectionManager.entities[domain.id]?.[name]\n if(connection) {\n return connection\n }\n\n if(domain.parentId) {\n return ConnectionManager.entities[domain.id]?.[name]\n } \n }\n\n static getConnectionInstances(domain: Domain): { [connectionName: string]: any } {\n const connections = ConnectionManager.connections[domain.id]\n const parentConnections = domain.parentId && ConnectionManager.connections[domain.parentId]\n\n return {\n ...parentConnections,\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"]}
@@ -4,11 +4,17 @@ export declare class PostgresqlConnector implements Connector {
4
4
  ready(connectionConfigs: InputConnection[]): Promise<void>;
5
5
  connect(connection: InputConnection): Promise<void>;
6
6
  disconnect(connection: InputConnection): Promise<void>;
7
- get parameterSpec(): {
7
+ get parameterSpec(): ({
8
8
  type: string;
9
9
  name: string;
10
10
  label: string;
11
- }[];
11
+ placeHolder?: undefined;
12
+ } | {
13
+ type: string;
14
+ name: string;
15
+ label: string;
16
+ placeHolder: string;
17
+ })[];
12
18
  get taskPrefixes(): string[];
13
19
  get help(): string;
14
20
  }
@@ -4,7 +4,7 @@ exports.PostgresqlConnector = void 0;
4
4
  const env_1 = require("@things-factory/env");
5
5
  const connection_manager_1 = require("../connection-manager");
6
6
  try {
7
- var { Client } = require('pg');
7
+ var { Client, Pool } = require('pg');
8
8
  }
9
9
  catch (err) {
10
10
  env_1.logger.error('postgresql module loading failed', err);
@@ -15,30 +15,60 @@ class PostgresqlConnector {
15
15
  connection_manager_1.ConnectionManager.logger.info('postgresql-connector connections are ready');
16
16
  }
17
17
  async connect(connection) {
18
- const { endpoint, params: { user, password, database } } = connection;
18
+ const { endpoint, params: { user, password, database, maxPoolConnection, idleTimeoutMillis, connectionTimeoutMillis } } = connection;
19
19
  const [host, port = 5432] = endpoint.split(':');
20
- if (!Client) {
20
+ if (!Pool) {
21
21
  throw new Error('postgresql module loading failed');
22
22
  }
23
- const client = new Client({
23
+ // create a new pool
24
+ const pool = new Pool({
24
25
  user,
25
26
  host,
26
27
  database,
27
28
  password,
28
- port: Number(port)
29
+ port: Number(port),
30
+ max: maxPoolConnection || 10,
31
+ idleTimeoutMillis: idleTimeoutMillis || 30000,
32
+ connectionTimeoutMillis: connectionTimeoutMillis || 2000
29
33
  });
30
- client.on('error', async (err) => {
31
- // create a new database clinet and reconnect to server at an unexpected error
32
- this.connect(connection);
34
+ pool.on('error', (err, client) => {
35
+ env_1.logger.error('unexpected error on postgres pool.', err);
33
36
  });
34
37
  try {
35
- await client.connect();
38
+ // try to connect to database to check the connection at initial time
39
+ const entryConnection = await pool.connect().catch(async (e) => {
40
+ connection_manager_1.ConnectionManager.logger.error(e);
41
+ throw e;
42
+ });
43
+ entryConnection.release();
36
44
  connection_manager_1.ConnectionManager.addConnectionInstance(connection, {
37
45
  query: async (query, params) => {
38
- return (await client.query(query, params)).rows;
46
+ try {
47
+ // get a connection from the pool
48
+ var client = await pool.connect().catch(async (e) => {
49
+ connection_manager_1.ConnectionManager.logger.error(e);
50
+ throw e;
51
+ });
52
+ client === null || client === void 0 ? void 0 : client.on('error', async (err) => {
53
+ env_1.logger.error('unexpected error on postgres client.', err);
54
+ connection_manager_1.ConnectionManager.logger.error(err);
55
+ });
56
+ // try to query
57
+ var result = (await client.query(query, params)).rows;
58
+ }
59
+ catch (e) {
60
+ connection_manager_1.ConnectionManager.logger.error(e);
61
+ throw e;
62
+ }
63
+ finally {
64
+ // release the connection back to the pool
65
+ client === null || client === void 0 ? void 0 : client.release();
66
+ }
67
+ return result;
39
68
  },
40
69
  close: async () => {
41
- await client.end();
70
+ // close the pool
71
+ await (pool === null || pool === void 0 ? void 0 : pool.end());
42
72
  }
43
73
  });
44
74
  connection_manager_1.ConnectionManager.logger.info(`PostgresSQL Database(${connection.name}:${database}) at ${endpoint} connected.`);
@@ -48,9 +78,9 @@ class PostgresqlConnector {
48
78
  }
49
79
  }
50
80
  async disconnect(connection) {
51
- var client = connection_manager_1.ConnectionManager.getConnectionInstance(connection);
81
+ var connectionInstance = connection_manager_1.ConnectionManager.getConnectionInstance(connection);
52
82
  try {
53
- await client.close();
83
+ await connectionInstance.close();
54
84
  connection_manager_1.ConnectionManager.logger.info(`PostgresSQL Database(${connection.name}) closed.`);
55
85
  }
56
86
  catch (e) {
@@ -74,6 +104,23 @@ class PostgresqlConnector {
74
104
  type: 'string',
75
105
  name: 'database',
76
106
  label: 'database'
107
+ },
108
+ {
109
+ type: 'number',
110
+ name: 'maxPoolConnection',
111
+ label: 'maxPoolConnection'
112
+ },
113
+ {
114
+ type: 'number',
115
+ name: 'idleTimeoutMillis',
116
+ label: 'idleTimeoutMillis',
117
+ placeHolder: 'milli-seconds'
118
+ },
119
+ {
120
+ type: 'number',
121
+ name: 'connectionTimeoutMillis',
122
+ label: 'connectionTimeoutMillis',
123
+ placeHolder: 'milli-seconds'
77
124
  }
78
125
  ];
79
126
  }
@@ -1 +1 @@
1
- {"version":3,"file":"postgresql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/postgresql-connector.ts"],"names":[],"mappings":";;;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B,KAAK,EAAE,UAAU;aAClB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,UAAU;aAClB;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,CAAC,CAAA;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,4CAA4C,CAAA;IACrD,CAAC;CACF;AAzFD,kDAyFC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,IAAI,mBAAmB,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('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"]}
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,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AACtC,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,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjE,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAA;IAC7E,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAA2B;QACvC,MAAM,EACJ,QAAQ,EACR,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,EACpG,GAAG,UAAU,CAAA;QACd,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE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,kBAAkB,CAAC,KAAK,EAAE,CAAA;YAChC,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,UAAU,CAAC,IAAI,WAAW,CAAC,CAAA;QACnF,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,sCAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACnC,CAAC;QACD,sCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;IACxD,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;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,UAAU;aAClB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,mBAAmB;gBACzB,KAAK,EAAE,mBAAmB;aAC3B;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,mBAAmB;gBACzB,KAAK,EAAE,mBAAmB;gBAC1B,WAAW,EAAE,eAAe;aAC7B;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,yBAAyB;gBAC/B,KAAK,EAAE,yBAAyB;gBAChC,WAAW,EAAE,eAAe;aAC7B;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,CAAC,CAAA;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,4CAA4C,CAAA;IACrD,CAAC;CACF;AAzID,kDAyIC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,IAAI,mBAAmB,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, Pool } = 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, maxPoolConnection, idleTimeoutMillis, connectionTimeoutMillis }\n } = connection\n const [host, port = 5432] = endpoint.split(':')\n\n if (!Pool) {\n throw new Error('postgresql module loading failed')\n }\n\n // create a new pool\n const pool = new Pool({\n user,\n host,\n database,\n password,\n port: Number(port),\n max: maxPoolConnection || 10,\n idleTimeoutMillis: idleTimeoutMillis || 30000,\n connectionTimeoutMillis: connectionTimeoutMillis || 2000\n })\n\n pool.on('error', (err, client) => {\n logger.error('unexpected error on postgres pool.', err)\n })\n\n try {\n // try to connect to database to check the connection at initial time\n const entryConnection = await pool.connect().catch(async e => {\n ConnectionManager.logger.error(e)\n throw e\n })\n entryConnection.release()\n\n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n try {\n // get a connection from the pool\n var client = await pool.connect().catch(async e => {\n ConnectionManager.logger.error(e)\n throw e\n })\n\n client?.on('error', async err => {\n logger.error('unexpected error on postgres client.', err)\n ConnectionManager.logger.error(err)\n })\n\n // try to query\n var result = (await client.query(query, params)).rows\n } catch (e) {\n ConnectionManager.logger.error(e)\n throw e\n } finally {\n // release the connection back to the pool\n client?.release()\n }\n return result\n },\n close: async () => {\n // close the pool\n await pool?.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 connectionInstance = ConnectionManager.getConnectionInstance(connection)\n try {\n await connectionInstance.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 type: 'number',\n name: 'maxPoolConnection',\n label: 'maxPoolConnection'\n },\n {\n type: 'number',\n name: 'idleTimeoutMillis',\n label: 'idleTimeoutMillis',\n placeHolder: 'milli-seconds'\n },\n {\n type: 'number',\n name: 'connectionTimeoutMillis',\n label: 'connectionTimeoutMillis',\n placeHolder: 'milli-seconds'\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"]}
@@ -22,6 +22,15 @@ export declare class Scenario {
22
22
  creatorId?: string;
23
23
  updater?: User;
24
24
  updaterId?: string;
25
- start(instanceName: any, variables?: any): Promise<void>;
26
- stop(instanceName?: any): Promise<void>;
25
+ start(options?: {
26
+ instanceName?: string;
27
+ domain?: Domain;
28
+ user?: User;
29
+ variables?: any;
30
+ }): Promise<void>;
31
+ stop(options?: {
32
+ instanceName?: string;
33
+ domain?: Domain;
34
+ user?: User;
35
+ }): Promise<void>;
27
36
  }
@@ -9,15 +9,19 @@ const shell_1 = require("@things-factory/shell");
9
9
  const engine_1 = require("../../engine");
10
10
  const step_type_1 = require("../step/step-type");
11
11
  let Scenario = class Scenario {
12
- async start(instanceName, variables) {
12
+ async start(options) {
13
13
  try {
14
- await engine_1.ScenarioEngine.load(instanceName || this.name, this, { domain: this.domain, user: this.updater, variables });
14
+ await engine_1.ScenarioEngine.load((options === null || options === void 0 ? void 0 : options.instanceName) || this.name, this, {
15
+ domain: (options === null || options === void 0 ? void 0 : options.domain) || this.domain,
16
+ user: (options === null || options === void 0 ? void 0 : options.user) || this.updater,
17
+ variables: options === null || options === void 0 ? void 0 : options.variables
18
+ });
15
19
  }
16
20
  catch (ex) { }
17
21
  }
18
- async stop(instanceName) {
22
+ async stop(options) {
19
23
  try {
20
- await engine_1.ScenarioEngine.unload(this.domain, instanceName || this.name);
24
+ await engine_1.ScenarioEngine.unload((options === null || options === void 0 ? void 0 : options.domain) || this.domain, (options === null || options === void 0 ? void 0 : options.instanceName) || this.name);
21
25
  }
22
26
  finally {
23
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scenario.js","sourceRoot":"","sources":["../../../server/service/scenario/scenario.ts"],"names":[],"mappings":";;;;AAAA,+CAAoE;AACpE,qCAUgB;AAEhB,yDAAiF;AACjF,iDAA8C;AAE9C,yCAA6C;AAC7C,iDAAwC;AAKjC,IAAM,QAAQ,GAAd,MAAM,QAAQ;IA8EnB,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,SAAe;QACvC,IAAI,CAAC;YACH,MAAM,uBAAc,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;QACpH,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC,CAAA,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,YAAa;QACtB,IAAI,CAAC;YACH,MAAM,uBAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,CAAA;QACrE,CAAC;gBAAS,CAAC;QACX,CAAC;IACH,CAAC;CACF,CAAA;AA1FY,4BAAQ;AAGnB;IAFC,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,CAAC;;oCACP;AAIX;IAFC,IAAA,mBAAS,EA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2CACnC;AAIlB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCAC9B,gBAAI;yCAAA;AAGd;IADC,IAAA,oBAAU,EAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;;2CACnC;mBA5EP,QAAQ;IAHpB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,eAAe,EAAE,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAClG,IAAA,yBAAU,GAAE;GACA,QAAQ,CA0FpB","sourcesContent":["import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'\nimport {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n OneToMany,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\n\nimport { PrivilegeObject, PrivilegeInput, User } from '@things-factory/auth-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { ScenarioEngine } from '../../engine'\nimport { Step } from '../step/step-type'\n\n@Entity()\n@Index('ix_scenario_0', (scenario: Scenario) => [scenario.domain, scenario.name], { unique: true })\n@ObjectType()\nexport class Scenario {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n id?: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain)\n domain?: Domain\n\n @RelationId((scenario: Scenario) => scenario.domain)\n domainId?: string\n\n @Column()\n @Field()\n name?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n description?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n type?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'accessible and executable system-wide' })\n public?: boolean\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: '[will be deprecated] automatically be started when this server start' })\n active?: boolean\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n schedule?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n scheduleId?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n timezone?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n ttl?: number\n\n @OneToMany(type => Step, step => step.scenario)\n @Field(type => [Step], { nullable: true })\n steps?: Step[]\n\n @Column({ type: 'simple-json', nullable: true })\n @Field(type => PrivilegeObject, { nullable: true })\n privilege?: PrivilegeObject\n\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true })\n creator?: User\n\n @RelationId((scenario: Scenario) => scenario.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true })\n updater?: User\n\n @RelationId((scenario: Scenario) => scenario.updater)\n updaterId?: string\n\n async start(instanceName, variables?: any) {\n try {\n await ScenarioEngine.load(instanceName || this.name, this, { domain: this.domain, user: this.updater, variables })\n } catch (ex) {}\n }\n\n async stop(instanceName?) {\n try {\n await ScenarioEngine.unload(this.domain, instanceName || this.name)\n } finally {\n }\n }\n}\n"]}
1
+ {"version":3,"file":"scenario.js","sourceRoot":"","sources":["../../../server/service/scenario/scenario.ts"],"names":[],"mappings":";;;;AAAA,+CAAoE;AACpE,qCAUgB;AAEhB,yDAAiF;AACjF,iDAA8C;AAE9C,yCAA6C;AAC7C,iDAAwC;AAKjC,IAAM,QAAQ,GAAd,MAAM,QAAQ;IA8EnB,KAAK,CAAC,KAAK,CAAC,OAKX;QACC,IAAI,CAAC;YACH,MAAM,uBAAc,CAAC,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,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AAK,EAAC,eAAe,EAAE,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAClG,IAAA,yBAAU,GAAE;GACA,QAAQ,CAyGpB","sourcesContent":["import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'\nimport {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n OneToMany,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\n\nimport { PrivilegeObject, PrivilegeInput, User } from '@things-factory/auth-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { ScenarioEngine } from '../../engine'\nimport { Step } from '../step/step-type'\n\n@Entity()\n@Index('ix_scenario_0', (scenario: Scenario) => [scenario.domain, scenario.name], { unique: true })\n@ObjectType()\nexport class Scenario {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n id?: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain)\n domain?: Domain\n\n @RelationId((scenario: Scenario) => scenario.domain)\n domainId?: string\n\n @Column()\n @Field()\n name?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n description?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n type?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'accessible and executable system-wide' })\n public?: boolean\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: '[will be deprecated] automatically be started when this server start' })\n active?: boolean\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n schedule?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n scheduleId?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n timezone?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n ttl?: number\n\n @OneToMany(type => Step, step => step.scenario)\n @Field(type => [Step], { nullable: true })\n steps?: Step[]\n\n @Column({ type: 'simple-json', nullable: true })\n @Field(type => PrivilegeObject, { nullable: true })\n privilege?: PrivilegeObject\n\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true })\n creator?: User\n\n @RelationId((scenario: Scenario) => scenario.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true })\n updater?: User\n\n @RelationId((scenario: Scenario) => scenario.updater)\n updaterId?: string\n\n async start(options?: {\n instanceName?: string;\n domain?: Domain;\n user?: User;\n variables?: any;\n }) {\n try {\n await ScenarioEngine.load(options?.instanceName || this.name, \n this, \n { \n domain: options?.domain || this.domain, \n user: options?.user || this.updater, \n variables: options?.variables \n })\n } catch (ex) {}\n }\n\n async stop(options?: {\n instanceName?: string;\n domain?: Domain,\n user?: User\n }) {\n try {\n await ScenarioEngine.unload(options?.domain || this.domain, options?.instanceName || this.name)\n } finally {\n }\n }\n}\n"]}