@things-factory/integration-base 7.0.0-alpha.0 → 7.0.0-alpha.18

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.
Files changed (202) hide show
  1. package/dist-server/controllers/index.js +5 -0
  2. package/dist-server/controllers/index.js.map +1 -0
  3. package/dist-server/controllers/scenario-controller.js +87 -0
  4. package/dist-server/controllers/scenario-controller.js.map +1 -0
  5. package/dist-server/engine/connection-manager.js +37 -6
  6. package/dist-server/engine/connection-manager.js.map +1 -1
  7. package/dist-server/engine/connector/echo-back-connector.js +1 -1
  8. package/dist-server/engine/connector/echo-back-connector.js.map +1 -1
  9. package/dist-server/engine/connector/echo-back-server.js +1 -1
  10. package/dist-server/engine/connector/echo-back-server.js.map +1 -1
  11. package/dist-server/engine/connector/graphql-connector.js +6 -6
  12. package/dist-server/engine/connector/graphql-connector.js.map +1 -1
  13. package/dist-server/engine/connector/http-connector.js.map +1 -1
  14. package/dist-server/engine/connector/mqtt-connector.js.map +1 -1
  15. package/dist-server/engine/connector/mssql-connector.js.map +1 -1
  16. package/dist-server/engine/connector/mysql-connector.js +3 -3
  17. package/dist-server/engine/connector/mysql-connector.js.map +1 -1
  18. package/dist-server/engine/connector/operato-connector.js +19 -22
  19. package/dist-server/engine/connector/operato-connector.js.map +1 -1
  20. package/dist-server/engine/connector/oracle-connector.js +113 -17
  21. package/dist-server/engine/connector/oracle-connector.js.map +1 -1
  22. package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
  23. package/dist-server/engine/connector/proxy-connector.js +44 -0
  24. package/dist-server/engine/connector/proxy-connector.js.map +1 -0
  25. package/dist-server/engine/connector/socket-server.js +1 -1
  26. package/dist-server/engine/connector/socket-server.js.map +1 -1
  27. package/dist-server/engine/connector/sqlite-connector.js.map +1 -1
  28. package/dist-server/engine/edge-client.js +38 -0
  29. package/dist-server/engine/edge-client.js.map +1 -0
  30. package/dist-server/engine/index.js +1 -0
  31. package/dist-server/engine/index.js.map +1 -1
  32. package/dist-server/engine/task/book-up-scenario.js.map +1 -1
  33. package/dist-server/engine/task/csv-readline.js.map +1 -1
  34. package/dist-server/engine/task/data-accessor.js.map +1 -1
  35. package/dist-server/engine/task/data-mapper.js.map +1 -1
  36. package/dist-server/engine/task/database-query.js.map +1 -1
  37. package/dist-server/engine/task/echo-receive.js.map +1 -1
  38. package/dist-server/engine/task/echo-send.js.map +1 -1
  39. package/dist-server/engine/task/empty-check.js.map +1 -1
  40. package/dist-server/engine/task/end.js.map +1 -1
  41. package/dist-server/engine/task/floating-point.js.map +1 -1
  42. package/dist-server/engine/task/goto.js.map +1 -1
  43. package/dist-server/engine/task/graphql-mutate.js.map +1 -1
  44. package/dist-server/engine/task/graphql-query.js.map +1 -1
  45. package/dist-server/engine/task/headless-post.js.map +1 -1
  46. package/dist-server/engine/task/headless-scrap.js.map +1 -1
  47. package/dist-server/engine/task/http-get.js.map +1 -1
  48. package/dist-server/engine/task/http-post.js.map +1 -1
  49. package/dist-server/engine/task/jsonata.js +1 -1
  50. package/dist-server/engine/task/jsonata.js.map +1 -1
  51. package/dist-server/engine/task/local-graphql-mutate.js.map +1 -1
  52. package/dist-server/engine/task/local-graphql-query.js.map +1 -1
  53. package/dist-server/engine/task/log.js.map +1 -1
  54. package/dist-server/engine/task/mqtt-publish.js.map +1 -1
  55. package/dist-server/engine/task/mqtt-subscribe.js.map +1 -1
  56. package/dist-server/engine/task/oracle-procedure.js +1 -15
  57. package/dist-server/engine/task/oracle-procedure.js.map +1 -1
  58. package/dist-server/engine/task/pick-pending-scenario.js.map +1 -1
  59. package/dist-server/engine/task/publish.js.map +1 -1
  60. package/dist-server/engine/task/random.js.map +1 -1
  61. package/dist-server/engine/task/reset-pending-queue.js.map +1 -1
  62. package/dist-server/engine/task/script.js +1 -0
  63. package/dist-server/engine/task/script.js.map +1 -1
  64. package/dist-server/engine/task/set-domain.js.map +1 -1
  65. package/dist-server/engine/task/sleep.js.map +1 -1
  66. package/dist-server/engine/task/socket-listener.js.map +1 -1
  67. package/dist-server/engine/task/state-read.js.map +1 -1
  68. package/dist-server/engine/task/state-write.js.map +1 -1
  69. package/dist-server/engine/task/stop-scenario.js.map +1 -1
  70. package/dist-server/engine/task/sub-scenario.js.map +1 -1
  71. package/dist-server/engine/task/switch-goto.js.map +1 -1
  72. package/dist-server/engine/task/switch-range-goto.js.map +1 -1
  73. package/dist-server/engine/task/switch-range-scenario.js.map +1 -1
  74. package/dist-server/engine/task/switch-range-set.js.map +1 -1
  75. package/dist-server/engine/task/switch-scenario.js.map +1 -1
  76. package/dist-server/engine/task/switch-set.js.map +1 -1
  77. package/dist-server/engine/task/throw.js.map +1 -1
  78. package/dist-server/engine/task/utils/headless-pool-for-scenario.js +1 -1
  79. package/dist-server/engine/task/utils/headless-pool-for-scenario.js.map +1 -1
  80. package/dist-server/engine/task/variables.js.map +1 -1
  81. package/dist-server/engine/types.js.map +1 -1
  82. package/dist-server/index.js +1 -0
  83. package/dist-server/index.js.map +1 -1
  84. package/dist-server/restful/unstable/run-scenario.js.map +1 -1
  85. package/dist-server/restful/unstable/start-scenario.js +1 -1
  86. package/dist-server/restful/unstable/start-scenario.js.map +1 -1
  87. package/dist-server/restful/unstable/stop-scenario.js +1 -1
  88. package/dist-server/restful/unstable/stop-scenario.js.map +1 -1
  89. package/dist-server/service/connection/connection-mutation.js +4 -8
  90. package/dist-server/service/connection/connection-mutation.js.map +1 -1
  91. package/dist-server/service/connection/connection-query.js +17 -14
  92. package/dist-server/service/connection/connection-query.js.map +1 -1
  93. package/dist-server/service/connection/connection-subscription.js +11 -14
  94. package/dist-server/service/connection/connection-subscription.js.map +1 -1
  95. package/dist-server/service/connection/connection-type.js +66 -13
  96. package/dist-server/service/connection/connection-type.js.map +1 -1
  97. package/dist-server/service/scenario-instance/scenario-instance-mutation.js +4 -71
  98. package/dist-server/service/scenario-instance/scenario-instance-mutation.js.map +1 -1
  99. package/dist-server/service/scenario-instance/scenario-instance-subscription.js +8 -9
  100. package/dist-server/service/scenario-instance/scenario-instance-subscription.js.map +1 -1
  101. package/dist-server/service/scenario-instance/scenario-instance-type.js +18 -5
  102. package/dist-server/service/scenario-instance/scenario-instance-type.js.map +1 -1
  103. package/dist-server/service/scenario-queue/scenario-queue-subscription.js +4 -4
  104. package/dist-server/service/scenario-queue/scenario-queue-subscription.js.map +1 -1
  105. package/dist-server/service/step/step-type.js +41 -28
  106. package/dist-server/service/step/step-type.js.map +1 -1
  107. package/dist-server/tsconfig.tsbuildinfo +1 -1
  108. package/helps/integration/concept/script-internal-variables.ja.md +21 -1
  109. package/helps/integration/concept/script-internal-variables.ko.md +17 -0
  110. package/helps/integration/concept/script-internal-variables.md +18 -0
  111. package/helps/integration/concept/script-internal-variables.ms.md +19 -1
  112. package/helps/integration/concept/script-internal-variables.zh.md +18 -0
  113. package/helps/integration/connector/oracle-connector.ja.md +90 -0
  114. package/helps/integration/connector/oracle-connector.ko.md +87 -0
  115. package/helps/integration/connector/oracle-connector.md +46 -25
  116. package/helps/integration/connector/oracle-connector.ms.md +87 -0
  117. package/helps/integration/connector/oracle-connector.zh.md +87 -0
  118. package/helps/integration/task/script.ja.md +1 -1
  119. package/helps/integration/task/script.ko.md +1 -1
  120. package/helps/integration/task/script.md +1 -1
  121. package/helps/integration/task/script.ms.md +1 -1
  122. package/helps/integration/task/script.zh.md +1 -1
  123. package/openapi/unstable/scenario.yaml +100 -100
  124. package/openapi/unstable.yaml +11 -11
  125. package/package.json +8 -11
  126. package/server/controllers/index.ts +1 -0
  127. package/server/controllers/scenario-controller.ts +116 -0
  128. package/server/engine/connection-manager.ts +49 -7
  129. package/server/engine/connector/echo-back-connector.ts +4 -3
  130. package/server/engine/connector/echo-back-server.ts +5 -4
  131. package/server/engine/connector/graphql-connector.ts +12 -13
  132. package/server/engine/connector/http-connector.ts +4 -3
  133. package/server/engine/connector/mqtt-connector.ts +4 -3
  134. package/server/engine/connector/mssql-connector.ts +4 -3
  135. package/server/engine/connector/mysql-connector.ts +8 -6
  136. package/server/engine/connector/operato-connector.ts +27 -35
  137. package/server/engine/connector/oracle-connector.ts +136 -23
  138. package/server/engine/connector/postgresql-connector.ts +4 -3
  139. package/server/engine/connector/proxy-connector.ts +53 -0
  140. package/server/engine/connector/socket-server.ts +5 -4
  141. package/server/engine/connector/sqlite-connector.ts +5 -3
  142. package/server/engine/edge-client.ts +45 -0
  143. package/server/engine/index.ts +1 -0
  144. package/server/engine/task/book-up-scenario.ts +3 -1
  145. package/server/engine/task/csv-readline.ts +4 -1
  146. package/server/engine/task/data-accessor.ts +4 -1
  147. package/server/engine/task/data-mapper.ts +4 -1
  148. package/server/engine/task/database-query.ts +3 -1
  149. package/server/engine/task/echo-receive.ts +4 -1
  150. package/server/engine/task/echo-send.ts +3 -1
  151. package/server/engine/task/empty-check.ts +4 -1
  152. package/server/engine/task/end.ts +4 -1
  153. package/server/engine/task/floating-point.ts +4 -1
  154. package/server/engine/task/goto.ts +4 -1
  155. package/server/engine/task/graphql-mutate.ts +3 -1
  156. package/server/engine/task/graphql-query.ts +3 -1
  157. package/server/engine/task/headless-post.ts +4 -1
  158. package/server/engine/task/headless-scrap.ts +3 -1
  159. package/server/engine/task/http-get.ts +3 -1
  160. package/server/engine/task/http-post.ts +3 -1
  161. package/server/engine/task/jsonata.ts +5 -2
  162. package/server/engine/task/local-graphql-mutate.ts +5 -1
  163. package/server/engine/task/local-graphql-query.ts +3 -1
  164. package/server/engine/task/log.ts +3 -1
  165. package/server/engine/task/mqtt-publish.ts +3 -1
  166. package/server/engine/task/mqtt-subscribe.ts +3 -1
  167. package/server/engine/task/oracle-procedure.ts +4 -17
  168. package/server/engine/task/pick-pending-scenario.ts +3 -1
  169. package/server/engine/task/publish.ts +3 -1
  170. package/server/engine/task/random.ts +4 -1
  171. package/server/engine/task/reset-pending-queue.ts +3 -1
  172. package/server/engine/task/script.ts +5 -1
  173. package/server/engine/task/set-domain.ts +4 -1
  174. package/server/engine/task/sleep.ts +3 -1
  175. package/server/engine/task/socket-listener.ts +3 -1
  176. package/server/engine/task/state-read.ts +3 -1
  177. package/server/engine/task/state-write.ts +3 -1
  178. package/server/engine/task/stop-scenario.ts +3 -1
  179. package/server/engine/task/sub-scenario.ts +3 -1
  180. package/server/engine/task/switch-goto.ts +4 -1
  181. package/server/engine/task/switch-range-goto.ts +3 -1
  182. package/server/engine/task/switch-range-scenario.ts +3 -1
  183. package/server/engine/task/switch-range-set.ts +3 -1
  184. package/server/engine/task/switch-scenario.ts +3 -1
  185. package/server/engine/task/switch-set.ts +3 -1
  186. package/server/engine/task/throw.ts +3 -1
  187. package/server/engine/task/utils/headless-pool-for-scenario.ts +1 -1
  188. package/server/engine/task/variables.ts +3 -1
  189. package/server/engine/types.ts +80 -4
  190. package/server/index.ts +1 -0
  191. package/server/restful/unstable/run-scenario.ts +0 -1
  192. package/server/restful/unstable/start-scenario.ts +1 -1
  193. package/server/restful/unstable/stop-scenario.ts +1 -1
  194. package/server/service/connection/connection-mutation.ts +9 -29
  195. package/server/service/connection/connection-query.ts +13 -12
  196. package/server/service/connection/connection-subscription.ts +18 -24
  197. package/server/service/connection/connection-type.ts +100 -21
  198. package/server/service/scenario-instance/scenario-instance-mutation.ts +10 -121
  199. package/server/service/scenario-instance/scenario-instance-subscription.ts +16 -23
  200. package/server/service/scenario-instance/scenario-instance-type.ts +24 -13
  201. package/server/service/scenario-queue/scenario-queue-subscription.ts +7 -7
  202. package/server/service/step/step-type.ts +78 -22
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
5
5
  require("cross-fetch/polyfill");
6
6
  const core_1 = require("@apollo/client/core");
7
7
  const context_1 = require("@apollo/client/link/context");
8
- // for subscription
9
8
  const ws_1 = tslib_1.__importDefault(require("ws"));
10
9
  const graphql_ws_1 = require("graphql-ws");
11
10
  const subscriptions_1 = require("@apollo/client/link/subscriptions");
@@ -16,7 +15,7 @@ const scenario_1 = require("../../service/scenario/scenario");
16
15
  const scenario_instance_type_1 = require("../../service/scenario-instance/scenario-instance-type");
17
16
  const shell_1 = require("@things-factory/shell");
18
17
  const auth_base_1 = require("@things-factory/auth-base");
19
- const debug = require('debug')('things-factory:integration-base:operato-connector-subscription');
18
+ const debug = require('debug')('things-factory:integration-base:operato-connector');
20
19
  const defaultOptions = {
21
20
  watchQuery: {
22
21
  fetchPolicy: 'no-cache',
@@ -30,24 +29,19 @@ const defaultOptions = {
30
29
  errorPolicy: 'all'
31
30
  }
32
31
  };
33
- const cache = new core_1.InMemoryCache({
34
- addTypename: false
35
- });
36
32
  exports.GRAPHQL_URI = '/graphql';
37
33
  exports.SUBSCRIPTION_URI = exports.GRAPHQL_URI;
38
- ;
39
- ``;
40
34
  class OperatoConnector {
41
35
  async ready(connectionConfigs) {
42
36
  await Promise.all(connectionConfigs.map(this.connect.bind(this)));
43
- connection_manager_1.ConnectionManager.logger.info('graphql-connector connections are ready');
37
+ connection_manager_1.ConnectionManager.logger.info('operato-connector connections are ready');
44
38
  }
45
39
  async connect(connection) {
46
- var { endpoint: uri, params: { authKey, domain, subscriptionHandlers = {} } } = connection;
40
+ const { endpoint: uri, params: { authKey, domain, subscriptionHandlers = {} } } = connection;
47
41
  if (!authKey || !domain) {
48
42
  throw new Error('some connection paramter missing.');
49
43
  }
50
- var domainOwner = await (0, shell_1.getRepository)(auth_base_1.User).findOne({
44
+ const domainOwner = await (0, shell_1.getRepository)(auth_base_1.User).findOne({
51
45
  where: {
52
46
  id: connection.domain.owner
53
47
  }
@@ -88,18 +82,21 @@ class OperatoConnector {
88
82
  headers: Object.assign(Object.assign({}, headers), { 'x-things-factory-domain': domain, authorization: authKey ? `Bearer ${authKey}` : '' })
89
83
  };
90
84
  }).concat(httpLink));
91
- var client = new core_1.ApolloClient({
85
+ const cache = new core_1.InMemoryCache({
86
+ addTypename: false
87
+ });
88
+ const client = new core_1.ApolloClient({
92
89
  defaultOptions,
93
90
  cache,
94
91
  link: splitLink
95
92
  });
96
- var subscriptions = [];
93
+ const subscriptions = [];
97
94
  Object.keys(subscriptionHandlers).forEach(async (tag) => {
98
95
  if (!tag || !subscriptionHandlers[tag])
99
96
  return;
100
- let scenarioName = subscriptionHandlers[tag];
97
+ const scenarioName = subscriptionHandlers[tag];
101
98
  // fetch a scenario
102
- var selectedScenario = await (0, shell_1.getRepository)(scenario_1.Scenario).findOne({
99
+ const selectedScenario = await (0, shell_1.getRepository)(scenario_1.Scenario).findOne({
103
100
  where: {
104
101
  name: scenarioName
105
102
  },
@@ -115,7 +112,7 @@ class OperatoConnector {
115
112
  }
116
113
  `
117
114
  });
118
- var subscriptionObserver = subscription.subscribe({
115
+ const subscriptionObserver = subscription.subscribe({
119
116
  next: async (data) => {
120
117
  var _a;
121
118
  debug('received pubsub msg.:', data === null || data === void 0 ? void 0 : data.data);
@@ -138,15 +135,15 @@ class OperatoConnector {
138
135
  });
139
136
  client['subscriptions'] = subscriptions;
140
137
  connection_manager_1.ConnectionManager.addConnectionInstance(connection, client);
141
- connection_manager_1.ConnectionManager.logger.info(`graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`);
138
+ connection_manager_1.ConnectionManager.logger.info(`operato-connector connection(${connection.name}:${connection.endpoint}) is connected`);
142
139
  }
143
140
  async disconnect(connection) {
144
- var client = connection_manager_1.ConnectionManager.getConnectionInstance(connection);
145
- let subscriptions = client['subscriptions'];
141
+ const client = connection_manager_1.ConnectionManager.getConnectionInstance(connection);
142
+ const subscriptions = client['subscriptions'];
146
143
  subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe());
147
144
  client.stop();
148
145
  connection_manager_1.ConnectionManager.removeConnectionInstance(connection);
149
- connection_manager_1.ConnectionManager.logger.info(`graphql-connector connection(${connection.name}) is disconnected`);
146
+ connection_manager_1.ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`);
150
147
  }
151
148
  async runScenario(subscriptions, variables) {
152
149
  var _a;
@@ -155,7 +152,7 @@ class OperatoConnector {
155
152
  if (!tag) {
156
153
  throw new Error(`tag is invalid - ${tag}`);
157
154
  }
158
- var scenario = (_a = subscriptions.find(subscription => subscription.tag === tag)) === null || _a === void 0 ? void 0 : _a.scenario;
155
+ const scenario = (_a = subscriptions.find(subscription => subscription.tag === tag)) === null || _a === void 0 ? void 0 : _a.scenario;
159
156
  if (!scenario) {
160
157
  throw new Error(`scenario is not found - ${tag}`);
161
158
  }
@@ -164,8 +161,8 @@ class OperatoConnector {
164
161
  throw new Error(`Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`);
165
162
  }
166
163
  /* create a scenario instance */
167
- let instanceName = scenario.name + '-' + String(Date.now());
168
- var instance = new scenario_instance_type_1.ScenarioInstance(instanceName, scenario, {
164
+ const instanceName = scenario.name + '-' + String(Date.now());
165
+ const instance = new scenario_instance_type_1.ScenarioInstance(instanceName, scenario, {
169
166
  user,
170
167
  domain,
171
168
  variables,
@@ -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,mBAAmB;AACnB,oDAA0B;AAC1B,2CAAyC;AACzC,qEAAiE;AACjE,wDAA4D;AAC5D,sEAA6B;AAE7B,8DAAyD;AAEzD,8DAA0D;AAC1D,mGAAyF;AAEzF,iDAAiF;AACjF,yDAAiE;AAEjE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,gEAAgE,CAAC,CAAA;AAEhG,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,MAAM,KAAK,GAAG,IAAI,oBAAa,CAAC;IAC9B,WAAW,EAAE,KAAK;CACnB,CAAC,CAAA;AAEW,QAAA,WAAW,GAAG,UAAU,CAAA;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I,IAAI;QACN,OAAO,yCAAyC,CAAA;IAClD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,2BAA2B,CAAA;IACpC,CAAC;CACF;AAxND,4CAwNC;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\n// for subscription\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 { 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-subscription')\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\nconst cache = new InMemoryCache({\n addTypename: false\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;``\n\nexport class OperatoConnector implements Connector {\n private context: any\n\n async ready(connectionConfigs) {\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) {\n var {\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 var 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 var client = new ApolloClient({\n defaultOptions,\n cache,\n link: splitLink\n })\n\n var subscriptions: SubscriberData[] = []\n Object.keys(subscriptionHandlers).forEach(async tag => {\n if (!tag || !subscriptionHandlers[tag]) return\n\n let scenarioName = subscriptionHandlers[tag]\n\n // fetch a scenario\n var 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 var 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 `graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n let subscriptions: SubscriberData[] = client['subscriptions']\n subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())\n client.stop()\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`graphql-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 var 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! ${\n category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'\n } required`\n )\n }\n\n /* create a scenario instance */\n let instanceName = scenario.name + '-' + String(Date.now())\n var 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;QACvB,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAEY,QAAA,WAAW,GAAG,UAAU,CAAA;AACxB,QAAA,gBAAgB,GAAG,mBAAW,CAAA;AAQ3C,MAAa,gBAAgB;IAG3B,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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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"]}
@@ -4,7 +4,7 @@ exports.OracleConnector = 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('oracledb');
7
+ var oracledb = require('oracledb');
8
8
  }
9
9
  catch (err) {
10
10
  env_1.logger.error('oracledb module loading failed');
@@ -14,33 +14,108 @@ class OracleConnector {
14
14
  await Promise.all(connectionConfigs.map(this.connect));
15
15
  connection_manager_1.ConnectionManager.logger.info('oracle-connector connections are ready');
16
16
  }
17
+ async recreatePool(connection) {
18
+ const { name, endpoint, params: { user, password, database, poolMin, poolMax, poolIncrement }, domain } = connection;
19
+ if (!oracledb) {
20
+ throw new Error('oracledb module loading failed');
21
+ }
22
+ const poolAlias = `${domain.name}-${name}`;
23
+ await oracledb.getPool(poolAlias).close(10);
24
+ await oracledb.createPool({
25
+ user,
26
+ password,
27
+ // when oracle not using default port must add connection string with port like localhost:port
28
+ connectString: `${endpoint.trim()}/${database}`,
29
+ poolMin,
30
+ poolMax,
31
+ poolIncrement,
32
+ poolAlias
33
+ });
34
+ connection_manager_1.ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`);
35
+ }
17
36
  async connect(connection) {
18
- const { endpoint, params: { user, password, database } } = connection;
19
- if (!Client) {
37
+ const { name, endpoint, params: { user, password, database, poolMin, poolMax, poolIncrement }, domain } = connection;
38
+ if (!oracledb) {
20
39
  throw new Error('oracledb module loading failed');
21
40
  }
22
- //when oracle not using default port must add connection string with port like localhsot:port
23
- const client = await Client.getConnection({
41
+ const poolAlias = `${domain.name}-${name}`;
42
+ var enableStatistics = true;
43
+ const pool = await oracledb.createPool({
24
44
  user,
25
45
  password,
26
- connectString: `${endpoint.trim()}/${database}`
46
+ // when oracle not using default port must add connection string with port like localhost:port
47
+ connectString: `${endpoint.trim()}/${database}`,
48
+ poolMin,
49
+ poolMax,
50
+ poolIncrement,
51
+ poolAlias,
52
+ enableStatistics
27
53
  });
28
54
  connection_manager_1.ConnectionManager.addConnectionInstance(connection, {
29
55
  query: async (query, params) => {
30
- return (await client.execute(query, params, {
31
- outFormat: Client.OBJECT
32
- })).rows;
56
+ let dbConnection = {};
57
+ let taskResult = {};
58
+ try {
59
+ dbConnection = await oracledb.getConnection(poolAlias);
60
+ taskResult = (await dbConnection.execute(query, params, {
61
+ outFormat: oracledb.OBJECT
62
+ })).rows;
63
+ }
64
+ catch (e) {
65
+ if (e.name === 'Error' && e.message.includes('NJS-040')) {
66
+ await this.recreatePool(connection);
67
+ }
68
+ throw e;
69
+ }
70
+ finally {
71
+ await dbConnection.close();
72
+ }
73
+ return taskResult;
33
74
  },
34
75
  execute: async (procedure, params) => {
35
- // TODO: need to check if this is available when procedure string is a common query.
36
- procedure = `BEGIN
37
- ${procedure}
38
- END;`;
39
- return await client.execute(procedure, params, {
40
- outFormat: Client.OBJECT
41
- });
76
+ let dbConnection = {};
77
+ let taskResult = {};
78
+ try {
79
+ // TODO: need to check if this is available when procedure string is a common query.
80
+ procedure = `BEGIN
81
+ ${procedure}
82
+ END;`;
83
+ dbConnection = await oracledb.getConnection(poolAlias);
84
+ // console.log('\n************* stat after get ****************')
85
+ // await oracledb.getPool(poolAlias).logStatistics()
86
+ const result = await dbConnection.execute(procedure, params, {
87
+ outFormat: oracledb.OBJECT
88
+ });
89
+ let paramKeys = Object.keys(params);
90
+ for (const paramKey of paramKeys) {
91
+ if (params[paramKey].dir === (oracledb === null || oracledb === void 0 ? void 0 : oracledb.BIND_OUT)) {
92
+ if (params[paramKey].type === (oracledb === null || oracledb === void 0 ? void 0 : oracledb.CURSOR)) {
93
+ const resultSetTemp = result.outBinds[paramKey];
94
+ taskResult[paramKey] = await resultSetTemp.getRows();
95
+ await resultSetTemp.close();
96
+ }
97
+ else {
98
+ taskResult[paramKey] = result.outBinds[paramKey];
99
+ }
100
+ }
101
+ }
102
+ }
103
+ catch (e) {
104
+ if (e.name === 'Error' && e.message.includes('NJS-040')) {
105
+ await this.recreatePool(connection);
106
+ }
107
+ throw e;
108
+ }
109
+ finally {
110
+ await dbConnection.close();
111
+ // console.log('\n************* stat after close ****************')
112
+ // await oracledb.getPool(poolAlias).logStatistics()
113
+ }
114
+ return taskResult;
42
115
  },
43
- close: client.close.bind(client)
116
+ close: async () => {
117
+ await oracledb.getPool(poolAlias).close(10);
118
+ }
44
119
  });
45
120
  connection_manager_1.ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`);
46
121
  }
@@ -72,6 +147,27 @@ class OracleConnector {
72
147
  name: 'database',
73
148
  placeholder: 'SID',
74
149
  label: 'database'
150
+ },
151
+ {
152
+ type: 'number',
153
+ name: 'poolMin',
154
+ placeholder: 'minimum connection-pool size',
155
+ label: 'pool-min',
156
+ value: 0
157
+ },
158
+ {
159
+ type: 'number',
160
+ name: 'poolMax',
161
+ placeholder: 'maximum connection-pool size',
162
+ label: 'pool-max',
163
+ value: 4
164
+ },
165
+ {
166
+ type: 'number',
167
+ name: 'poolIncrement',
168
+ placeholder: 'connection incremental size',
169
+ label: 'pool-increment',
170
+ value: 1
75
171
  }
76
172
  ];
77
173
  }
@@ -1 +1 @@
1
- {"version":3,"file":"oracle-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/oracle-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAGzD,IAAI;IACF,IAAI,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CACjC;AAAC,OAAO,GAAG,EAAE;IACZ,YAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;CAC/C;AAED,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAEtD,sCAAiB,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UAAU;QACzB,IAAI,MAAM,GAAG,sCAAiB,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAA;QAChE,IAAI;YACF,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;YACpB,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,UAAU,CAAC,IAAI,WAAW,CAAC,CAAA;SAC7E;QAAC,OAAO,CAAC,EAAE;YACV,sCAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;SAClC;QAED,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,WAAW,EAAE,KAAK;gBAClB,KAAK,EAAE,UAAU;aAClB;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;AAxFD,0CAwFC;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'\n\ntry {\n var Client = require('oracledb')\n} catch (err) {\n logger.error('oracledb module loading failed')\n}\n\nexport class OracleConnector implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('oracle-connector connections are ready')\n }\n\n async connect(connection) {\n const {\n endpoint,\n params: { user, password, database }\n } = connection\n\n if (!Client) {\n throw new Error('oracledb module loading failed')\n }\n\n //when oracle not using default port must add connection string with port like localhsot:port\n const client = await Client.getConnection({\n user,\n password,\n connectString: `${endpoint.trim()}/${database}`\n })\n\n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n return (\n await client.execute(query, params, {\n outFormat: Client.OBJECT\n })\n ).rows\n },\n execute: async (procedure, params) => {\n // TODO: need to check if this is available when procedure string is a common query.\n procedure = `BEGIN\n ${procedure}\n END;`\n\n return await client.execute(procedure, params, {\n outFormat: Client.OBJECT\n })\n },\n close: client.close.bind(client)\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`)\n }\n\n async disconnect(connection) {\n var client = ConnectionManager.getConnectionInstance(connection)\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 }\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;IACF,IAAI,QAAQ,G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UAAU;gBAChB,WAAW,EAAE,KAAK;gBAClB,KAAK,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;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 +1 @@
1
- {"version":3,"file":"postgresql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/postgresql-connector.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AU;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;AAxFD,kDAwFC;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'\n\ntry {\n var { Client } = require('pg')\n} catch (err) {\n logger.error('postgresql module loading failed')\n}\n\nexport class PostgresqlConnector implements Connector {\n async ready(connectionConfigs) {\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) {\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.\\ncause: ${e}`\n )\n }\n }\n\n async disconnect(connection) {\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;IACF,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/B;AAAC,OAAO,GAAG,EAAE;IACZ,YAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAA;CACjD;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,EACrC,GAAG,UAAU,CAAA;QACd,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE/C,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;SACpD;QAED,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;YACxB,IAAI;YACJ,IAAI;YACJ,QAAQ;YACR,QAAQ;YACR,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;S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AAC,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;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;AAxFD,kDAwFC;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')\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.\\ncause: ${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"]}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProxyConnector = void 0;
4
+ const connection_manager_1 = require("../connection-manager");
5
+ const edge_client_1 = require("../edge-client");
6
+ /**
7
+ * This connector is a proxy connector installed on the edge server to manage connections from the host.
8
+ * It interacts with connections established on the edge server and provides synchronization functionality.
9
+ */
10
+ class ProxyConnector {
11
+ async ready(connectionConfigs) {
12
+ await Promise.all(connectionConfigs.map(this.connect.bind(this)));
13
+ connection_manager_1.ConnectionManager.logger.info('proxy-connector connections are ready');
14
+ }
15
+ async connect(connection) {
16
+ // TODO 원래 커넥션과 에지설정을 참고하여, 에지 서버로 CONNECT/DISCONNECT 명령을 보낸다.
17
+ const proxy = {
18
+ disconnect: async () => {
19
+ connection_manager_1.ConnectionManager.logger.info('[proxy-connector] trying disconnect');
20
+ await (0, edge_client_1.disconnectConnections)([connection]);
21
+ }
22
+ };
23
+ await (0, edge_client_1.connectConnections)([connection]);
24
+ connection_manager_1.ConnectionManager.addConnectionInstance(connection, proxy);
25
+ connection_manager_1.ConnectionManager.logger.info(`proxy-connector connection(${connection.name}:${connection.endpoint}) is connected`);
26
+ }
27
+ async disconnect(connection) {
28
+ const proxy = connection_manager_1.ConnectionManager.removeConnectionInstance(connection);
29
+ await proxy.disconnect();
30
+ connection_manager_1.ConnectionManager.logger.info(`proxy-connector connection(${connection.name}) is disconnected`);
31
+ }
32
+ get parameterSpec() {
33
+ return [];
34
+ }
35
+ get taskPrefixes() {
36
+ return [];
37
+ }
38
+ get description() {
39
+ return 'Operato Proxy Connector';
40
+ }
41
+ }
42
+ exports.ProxyConnector = ProxyConnector;
43
+ ProxyConnector.instance = new ProxyConnector();
44
+ //# sourceMappingURL=proxy-connector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/proxy-connector.ts"],"names":[],"mappings":";;;AAAA,8DAAyD;AAGzD,gDAA0E;AAE1E;;;GAGG;AACH,MAAa,cAAc;IAGzB,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,uCAAuC,CAAC,CAAA;IACxE,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAA2B;QACvC,8DAA8D;QAC9D,MAAM,KAAK,GAAG;YACZ,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAA;gBACpE,MAAM,IAAA,mCAAqB,EAAC,CAAC,UAAU,CAAC,CAAC,CAAA;YAC3C,CAAC;SACF,CAAA;QAED,MAAM,IAAA,gCAAkB,EAAC,CAAC,UAAU,CAAC,CAAC,CAAA;QAEtC,sCAAiB,CAAC,qBAAqB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;QAE1D,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,QAAQ,gBAAgB,CAAC,CAAA;IACrH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,UAA2B;QAC1C,MAAM,KAAK,GAAG,sCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;QACpE,MAAM,KAAK,CAAC,UAAU,EAAE,CAAA;QAExB,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,UAAU,CAAC,IAAI,mBAAmB,CAAC,CAAA;IACjG,CAAC;IAED,IAAI,aAAa;QACf,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,YAAY;QACd,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,WAAW;QACb,OAAO,yBAAyB,CAAA;IAClC,CAAC;;AA1CH,wCA2CC;AA1Ce,uBAAQ,GAAG,IAAI,cAAc,EAAE,CAAA","sourcesContent":["import { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\nimport { connectConnections, disconnectConnections } from '../edge-client'\n\n/**\n * This connector is a proxy connector installed on the edge server to manage connections from the host.\n * It interacts with connections established on the edge server and provides synchronization functionality.\n */\nexport class ProxyConnector implements Connector {\n public static instance = new ProxyConnector()\n\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('proxy-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n // TODO 원래 커넥션과 에지설정을 참고하여, 에지 서버로 CONNECT/DISCONNECT 명령을 보낸다.\n const proxy = {\n disconnect: async () => {\n ConnectionManager.logger.info('[proxy-connector] trying disconnect')\n await disconnectConnections([connection])\n }\n }\n\n await connectConnections([connection])\n\n ConnectionManager.addConnectionInstance(connection, proxy)\n\n ConnectionManager.logger.info(`proxy-connector connection(${connection.name}:${connection.endpoint}) is connected`)\n }\n\n async disconnect(connection: InputConnection) {\n const proxy = ConnectionManager.removeConnectionInstance(connection)\n await proxy.disconnect()\n\n ConnectionManager.logger.info(`proxy-connector connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return []\n }\n\n get taskPrefixes() {\n return []\n }\n\n get description() {\n return 'Operato Proxy Connector'\n }\n}\n"]}
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SocketServer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const net_1 = tslib_1.__importDefault(require("net"));
6
- const connection_manager_1 = require("../connection-manager");
7
6
  const events_1 = require("events");
7
+ const connection_manager_1 = require("../connection-manager");
8
8
  class SocketServer {
9
9
  // socket: any
10
10
  async ready(connectionConfigs) {
@@ -1 +1 @@
1
- {"version":3,"file":"socket-server.js","sourceRoot":"","sources":["../../../server/engine/connector/socket-server.ts"],"names":[],"mappings":";;;;AAAA,sDAAqB;AAGrB,8DAAyD;AACzD,mCAAqC;AAErC,MAAa,YAAY;IACvB,cAAc;IAEd,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,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,MAAM;QAClB,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,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AC,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'\n\nimport { Connector } from '../types'\nimport { ConnectionManager } from '../connection-manager'\nimport { EventEmitter } from 'events'\n\nexport class SocketServer implements Connector {\n // socket: any\n\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect))\n ConnectionManager.logger.info('socket servers are ready')\n }\n\n async connect(config): 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)\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) {\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"]}
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,C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M,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)\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"]}
@@ -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;AAGzD,IAAI;IACF,IAAI,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAA;CAC3C;AAAC,OAAO,GAAG,EAAE;IACZ,YAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAA;CAC9C;AAED,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,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,wCAAwC,CAAC,CAAA;IACzE,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAAU;QACtB,IAAI,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAA;QAE7B,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,+BAA+B,CA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AAO,wCAAwC,CAAA;IACjD,CAAC;CACF;AAtDD,0CAsDC;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'\n\ntry {\n var sqlite3 = require('sqlite3').verbose()\n} catch (err) {\n logger.error('sqlite3 module loading failed')\n}\n\nexport class SqliteConnector implements Connector {\n async ready(connectionConfigs) {\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) {\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(\n `SQLite Database(${connection.name}) at ${endpoint} not connected.\\ncause: ${err}`\n )\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) {\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"]}
1
+ {"version":3,"file":"sqlite-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/sqlite-connector.ts"],"names":[],"mappings":";;;AAAA,+BAAgC;AAEhC,6CAA4C;AAE5C,8DAAyD;AAKzD,IAAI;IACF,IAAI,OAA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CAAA;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,UAA2B;QAC1C,IAAI,QAAQ,GAAG,sCAAiB,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAA;QAClE,IAAI;YACF,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAA;YACtB,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,UAAU,CAAC,IAAI,WAAW,CAAC,CAAA;SAC7E;QAAC,OAAO,CAAC,EAAE;YACV,sCAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;SAClC;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;AAtDD,0CAsDC;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\n\ntry {\n var sqlite3 = require('sqlite3').verbose()\n} catch (err) {\n logger.error('sqlite3 module loading failed')\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(\n `SQLite Database(${connection.name}) at ${endpoint} not connected.\\ncause: ${err}`\n )\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"]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setEdgeClient = exports.disconnectConnections = exports.connectConnections = exports.syncConnections = exports.handler = void 0;
4
+ var edgeClient = {
5
+ async handler(step, scenarioContext) {
6
+ throw 'edgeClient not supported';
7
+ },
8
+ async syncConnections(connections, context) {
9
+ throw 'edgeClient not supported';
10
+ },
11
+ async connectConnections(connections, context) {
12
+ throw 'edgeClient not supported';
13
+ },
14
+ async disconnectConnections(connections, context) {
15
+ throw 'edgeClient not supported';
16
+ }
17
+ };
18
+ async function handler(step, scenarioContext) {
19
+ return await edgeClient.handler(step, scenarioContext);
20
+ }
21
+ exports.handler = handler;
22
+ async function syncConnections(connections, context) {
23
+ return await edgeClient.syncConnections(connections, context);
24
+ }
25
+ exports.syncConnections = syncConnections;
26
+ async function connectConnections(connections, context) {
27
+ return await edgeClient.connectConnections(connections, context);
28
+ }
29
+ exports.connectConnections = connectConnections;
30
+ async function disconnectConnections(connections, context) {
31
+ return await edgeClient.disconnectConnections(connections, context);
32
+ }
33
+ exports.disconnectConnections = disconnectConnections;
34
+ function setEdgeClient(edge) {
35
+ edgeClient = edge;
36
+ }
37
+ exports.setEdgeClient = setEdgeClient;
38
+ //# sourceMappingURL=edge-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-client.js","sourceRoot":"","sources":["../../server/engine/edge-client.ts"],"names":[],"mappings":";;;AAWA,IAAI,UAAU,GAAe;IAC3B,KAAK,CAAC,OAAO,CAAC,IAAU,EAAE,eAAwB;QAChD,MAAM,0BAA0B,CAAA;IAClC,CAAC;IACD,KAAK,CAAC,eAAe,CAAC,WAAyB,EAAE,OAAwB;QACvE,MAAM,0BAA0B,CAAA;IAClC,CAAC;IACD,KAAK,CAAC,kBAAkB,CAAC,WAAyB,EAAE,OAAwB;QAC1E,MAAM,0BAA0B,CAAA;IAClC,CAAC;IACD,KAAK,CAAC,qBAAqB,CAAC,WAAyB,EAAE,OAAwB;QAC7E,MAAM,0BAA0B,CAAA;IAClC,CAAC;CACF,CAAA;AAEM,KAAK,UAAU,OAAO,CAAC,IAAU,EAAE,eAAwB;IAChE,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,CAAA;AACxD,CAAC;AAFD,0BAEC;AAEM,KAAK,UAAU,eAAe,CAAC,WAAyB,EAAE,OAAyB;IACxF,OAAO,MAAM,UAAU,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AAC/D,CAAC;AAFD,0CAEC;AAEM,KAAK,UAAU,kBAAkB,CAAC,WAAyB,EAAE,OAAyB;IAC3F,OAAO,MAAM,UAAU,CAAC,kBAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AAClE,CAAC;AAFD,gDAEC;AAEM,KAAK,UAAU,qBAAqB,CAAC,WAAyB,EAAE,OAAyB;IAC9F,OAAO,MAAM,UAAU,CAAC,qBAAqB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AACrE,CAAC;AAFD,sDAEC;AAED,SAAgB,aAAa,CAAC,IAAgB;IAC5C,UAAU,GAAG,IAAI,CAAA;AACnB,CAAC;AAFD,sCAEC","sourcesContent":["import { Connection } from '../service/connection/connection-type'\nimport { Step } from '../service/step/step-type'\nimport { Context, TaskHandler } from './types'\n\nexport type EdgeClient = {\n handler: TaskHandler\n syncConnections(connections: Connection[], context?: ResolverContext): Promise<any>\n connectConnections(connections: Connection[], context?: ResolverContext): Promise<any>\n disconnectConnections(connections: Connection[], context?: ResolverContext): Promise<any>\n}\n\nvar edgeClient: EdgeClient = {\n async handler(step: Step, scenarioContext: Context) {\n throw 'edgeClient not supported'\n },\n async syncConnections(connections: Connection[], context: ResolverContext): Promise<any> {\n throw 'edgeClient not supported'\n },\n async connectConnections(connections: Connection[], context: ResolverContext): Promise<any> {\n throw 'edgeClient not supported'\n },\n async disconnectConnections(connections: Connection[], context: ResolverContext): Promise<any> {\n throw 'edgeClient not supported'\n }\n}\n\nexport async function handler(step: Step, scenarioContext: Context) {\n return await edgeClient.handler(step, scenarioContext)\n}\n\nexport async function syncConnections(connections: Connection[], context?: ResolverContext): Promise<any> {\n return await edgeClient.syncConnections(connections, context)\n}\n\nexport async function connectConnections(connections: Connection[], context?: ResolverContext): Promise<any> {\n return await edgeClient.connectConnections(connections, context)\n}\n\nexport async function disconnectConnections(connections: Connection[], context?: ResolverContext): Promise<any> {\n return await edgeClient.disconnectConnections(connections, context)\n}\n\nexport function setEdgeClient(edge: EdgeClient) {\n edgeClient = edge\n}\n"]}
@@ -7,4 +7,5 @@ tslib_1.__exportStar(require("./connection-manager"), exports);
7
7
  tslib_1.__exportStar(require("./scenario-engine"), exports);
8
8
  tslib_1.__exportStar(require("./task-registry"), exports);
9
9
  tslib_1.__exportStar(require("./analyzer/analyze-integration"), exports);
10
+ tslib_1.__exportStar(require("./edge-client"), exports);
10
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/engine/index.ts"],"names":[],"mappings":";;;AAAA,uBAAoB;AACpB,kBAAe;AAEf,+DAAoC;AACpC,4DAAiC;AACjC,0DAA+B;AAC/B,yEAA8C","sourcesContent":["import './connector'\nimport './task'\n\nexport * from './connection-manager'\nexport * from './scenario-engine'\nexport * from './task-registry'\nexport * from './analyzer/analyze-integration'\n\nexport { Connector } from './types'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/engine/index.ts"],"names":[],"mappings":";;;AAAA,uBAAoB;AACpB,kBAAe;AAEf,+DAAoC;AACpC,4DAAiC;AACjC,0DAA+B;AAC/B,yEAA8C;AAC9C,wDAA6B","sourcesContent":["import './connector'\nimport './task'\n\nexport * from './connection-manager'\nexport * from './scenario-engine'\nexport * from './task-registry'\nexport * from './analyzer/analyze-integration'\nexport * from './edge-client'\n\nexport { Connector } from './types'\n"]}