@things-factory/integration-base 9.0.15 → 9.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/engine/analyzer/analyze-integration.js +2 -2
- package/dist-server/engine/analyzer/analyze-integration.js.map +1 -1
- package/dist-server/engine/connection-manager.js +6 -4
- package/dist-server/engine/connection-manager.js.map +1 -1
- package/dist-server/engine/connector/headless-connector.d.ts +8 -0
- package/dist-server/engine/connector/headless-connector.js +4 -2
- package/dist-server/engine/connector/headless-connector.js.map +1 -1
- package/dist-server/engine/connector/mqtt-connector.d.ts +1 -0
- package/dist-server/engine/connector/mqtt-connector.js +4 -2
- package/dist-server/engine/connector/mqtt-connector.js.map +1 -1
- package/dist-server/engine/connector/mssql-connector.d.ts +4 -0
- package/dist-server/engine/connector/mssql-connector.js +4 -2
- package/dist-server/engine/connector/mssql-connector.js.map +1 -1
- package/dist-server/engine/connector/mysql-connector.d.ts +10 -2
- package/dist-server/engine/connector/mysql-connector.js +23 -18
- package/dist-server/engine/connector/mysql-connector.js.map +1 -1
- package/dist-server/engine/connector/operato-connector.d.ts +8 -2
- package/dist-server/engine/connector/operato-connector.js +2 -1
- package/dist-server/engine/connector/operato-connector.js.map +1 -1
- package/dist-server/engine/connector/oracle-connector.d.ts +3 -0
- package/dist-server/engine/connector/oracle-connector.js +4 -2
- package/dist-server/engine/connector/oracle-connector.js.map +1 -1
- package/dist-server/engine/connector/postgresql-connector.d.ts +13 -2
- package/dist-server/engine/connector/postgresql-connector.js +14 -6
- package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
- package/dist-server/engine/connector/pyrun-connector.d.ts +1 -0
- package/dist-server/engine/connector/pyrun-connector.js +3 -3
- package/dist-server/engine/connector/pyrun-connector.js.map +1 -1
- package/dist-server/engine/edge-client.d.ts +1 -1
- package/dist-server/engine/edge-client.js.map +1 -1
- package/dist-server/service/connection/connection-mutation.d.ts +2 -1
- package/dist-server/service/connection/connection-mutation.js +19 -18
- package/dist-server/service/connection/connection-mutation.js.map +1 -1
- package/dist-server/service/connection/connection-query.d.ts +2 -1
- package/dist-server/service/connection/connection-query.js +14 -13
- package/dist-server/service/connection/connection-query.js.map +1 -1
- package/dist-server/service/connection/connection-subscription.js +5 -4
- package/dist-server/service/connection/connection-subscription.js.map +1 -1
- package/dist-server/service/connection/connection-type.d.ts +6 -99
- package/dist-server/service/connection/connection-type.js +4 -181
- package/dist-server/service/connection/connection-type.js.map +1 -1
- package/dist-server/service/connection/connection.d.ts +115 -0
- package/dist-server/service/connection/connection.js +231 -0
- package/dist-server/service/connection/connection.js.map +1 -0
- package/dist-server/service/connection/index.d.ts +1 -1
- package/dist-server/service/connection/index.js +2 -2
- package/dist-server/service/connection/index.js.map +1 -1
- package/dist-server/service/connector/connector-query.js +2 -2
- package/dist-server/service/connector/connector-query.js.map +1 -1
- package/dist-server/service/index.d.ts +1 -0
- package/dist-server/service/index.js +1 -0
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/property-spec.d.ts +1 -0
- package/dist-server/service/property-spec.js +8 -1
- package/dist-server/service/property-spec.js.map +1 -1
- package/dist-server/service/scenario/scenario-query.js +3 -3
- package/dist-server/service/scenario/scenario-query.js.map +1 -1
- package/dist-server/service/task-type/task-type-query.js +2 -2
- package/dist-server/service/task-type/task-type-query.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"operato-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/operato-connector.ts"],"names":[],"mappings":";;;;AAAA,gCAA6B;AAE7B,8CAAwF;AACxF,yDAAwD;AAExD,oDAA0B;AAC1B,2CAAyC;AACzC,qEAAiE;AACjE,wDAA4D;AAC5D,sEAA6B;AAE7B,8DAAyD;AAIzD,8DAA0D;AAC1D,mGAAyF;AAEzF,iDAAiF;AACjF,yDAAkE;AAElE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,C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BAAsB;gBAC5B,KAAK,EAAE,uBAAuB;aAC/B;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,SAAS,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,yCAAyC,CAAA;IAClD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,2BAA2B,CAAA;IACpC,CAAC;CACF;AAvND,4CAuNC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAA","sourcesContent":["import 'cross-fetch/polyfill'\n\nimport { ApolloClient, InMemoryCache, createHttpLink, split } from '@apollo/client/core'\nimport { setContext } from '@apollo/client/link/context'\n\nimport WebSocket from 'ws'\nimport { createClient } from 'graphql-ws'\nimport { GraphQLWsLink } from '@apollo/client/link/subscriptions'\nimport { getMainDefinition } from '@apollo/client/utilities'\nimport gql from 'graphql-tag'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nimport { Scenario } from '../../service/scenario/scenario'\nimport { ScenarioInstance } from '../../service/scenario-instance/scenario-instance-type'\n\nimport { getRepository, GraphqlLocalClient, Domain } from '@things-factory/shell'\nimport { User, checkUserHasRole } from '@things-factory/auth-base'\n\nconst debug = require('debug')('things-factory:integration-base:operato-connector')\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache', //'network-only'\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nexport const GRAPHQL_URI = '/graphql'\nexport const SUBSCRIPTION_URI = GRAPHQL_URI\n\ninterface SubscriberData {\n tag: string\n scenario: any\n subscriptionObserver: any\n}\n\nexport class OperatoConnector implements Connector {\n private context: any\n\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('operato-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint: uri,\n params: { authKey, domain, subscriptionHandlers = {} }\n } = connection\n\n if (!authKey || !domain) {\n throw new Error('some connection paramter missing.')\n }\n\n const domainOwner = await getRepository(User).findOne({\n where: {\n id: connection.domain.owner\n }\n })\n\n this.context = {\n domain: connection.domain,\n user: domainOwner\n /* TODO: domainOwner 대신 특정 유저를 지정할 수 있도록 개선해야함. 모든 커넥션에 유저를 지정하는 기능으로 일반화할 필요가 있는 지 고민해야함 */\n }\n\n const httpLink = createHttpLink({\n uri: uri\n })\n\n /* \n CHECKPOINT: \n 1. GraphqQLWsLink를 사용하면 setContext를 통한 추가 헤더 설정이 무시됩니다.\n 따라서, GraphQLWsLink를 사용하려면, connectionParams를 통해 헤더를 설정해야 합니다.\n \n 2. 서버에서 실행시, webSocketImpl을 명시적으로 지정해야 합니다.\n */\n const wsLink = new GraphQLWsLink(\n createClient({\n url: uri.replace(/^http/, 'ws'),\n keepAlive: 10_000,\n retryAttempts: 1_000_000,\n shouldRetry: e => true,\n webSocketImpl: WebSocket,\n connectionParams: {\n headers: {\n 'x-things-factory-domain': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n })\n )\n\n const splitLink = split(\n ({ query }) => {\n const def = getMainDefinition(query)\n return def.kind === 'OperationDefinition' && def.operation === 'subscription'\n },\n wsLink,\n setContext((_, { headers }) => {\n return {\n headers: {\n ...headers,\n 'x-things-factory-domain': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n }).concat(httpLink)\n )\n\n const cache = new InMemoryCache({\n addTypename: false\n })\n\n const client = new ApolloClient({\n defaultOptions,\n cache,\n link: splitLink\n })\n\n const subscriptions: SubscriberData[] = []\n Object.keys(subscriptionHandlers).forEach(async tag => {\n if (!tag || !subscriptionHandlers[tag]) return\n\n const scenarioName = subscriptionHandlers[tag]\n\n // fetch a scenario\n const selectedScenario = await getRepository(Scenario).findOne({\n where: {\n name: scenarioName\n },\n relations: ['steps', 'domain']\n })\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n data(tag: \"${tag}\") {\n tag\n data\n }\n }\n `\n })\n\n const subscriptionObserver = subscription.subscribe({\n next: async data => {\n debug('received pubsub msg.:', data?.data)\n await this.runScenario(subscriptions, data?.data?.data)\n },\n error: error => {\n ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error`, error)\n },\n complete: () => {\n ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`)\n }\n })\n\n ConnectionManager.logger.info(\n `(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`\n )\n\n subscriptions.push({\n tag,\n scenario: selectedScenario,\n subscriptionObserver\n })\n ConnectionManager.logger.info(`(${tag}:${scenarioName}) subscription closed flag: ${subscriptionObserver.closed}`)\n })\n\n client['subscriptions'] = subscriptions\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(\n `operato-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection: InputConnection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n const subscriptions: SubscriberData[] = client['subscriptions']\n subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())\n client.stop()\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`)\n }\n\n async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {\n const { domain, user } = 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 checkUserHasRole(scenario.roleId, domain, user))) {\n throw new Error(`Unauthorized! ${scenario.name} doesn't have required role.`)\n }\n\n /* create a scenario instance */\n const instanceName = scenario.name + '-' + String(Date.now())\n const instance = new ScenarioInstance(instanceName, scenario, {\n user,\n domain,\n variables,\n client: GraphqlLocalClient.client\n })\n\n // run scenario\n await instance.run()\n return instance\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'authKey',\n label: 'auth-key'\n },\n {\n type: 'string',\n name: 'domain',\n label: 'domain'\n },\n {\n type: 'tag-scenarios',\n name: 'subscriptionHandlers',\n label: 'subscription-handlers'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['graphql']\n }\n\n get help() {\n return 'integration/connector/operato-connector'\n }\n\n get description() {\n return 'Operato Graphql Connector'\n }\n}\n\nConnectionManager.registerConnector('operato-connector', new OperatoConnector())\n"]}
|
1
|
+
{"version":3,"file":"operato-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/operato-connector.ts"],"names":[],"mappings":";;;;AAAA,gCAA6B;AAE7B,8CAAwF;AACxF,yDAAwD;AAExD,oDAA0B;AAC1B,2CAAyC;AACzC,qEAAiE;AACjE,wDAA4D;AAC5D,sEAA6B;AAE7B,8DAAyD;AAIzD,8DAA0D;AAC1D,mGAAyF;AAEzF,iDAAiF;AACjF,yDAAkE;AAElE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,mDAAmD,CAAC,CAAA;AAEnF,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU,EAAE,gBAAgB;QACzC,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;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,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C7D,MAAM,IAAI,KAAK,CAAC,iBAAiB,QAAQ,CAAC,IAAI,8BAA8B,CAAC,CAAA;QAC/E,CAAC;QAED,gCAAgC;QAChC,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAC7D,MAAM,QAAQ,GAAG,IAAI,yCAAgB,CAAC,YAAY,EAAE,QAAQ,EAAE;YAC5D,IAAI;YACJ,MAAM;YACN,SAAS;YACT,MAAM,EAAE,0BAAkB,CAAC,MAAM;SAClC,CAAC,CAAA;QAEF,eAAe;QACf,MAAM,QAAQ,CAAC,GAAG,EAAE,CAAA;QACpB,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,IAAI,aAAa;QACf,OAAO;YACL;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,UAAU;gBACjB,kBAAkB,EAAE,IAAI;aACzB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,QAAQ;aAChB;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,sBAAsB;gBAC5B,KAAK,EAAE,uBAAuB;aAC/B;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,SAAS,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,yCAAyC,CAAA;IAClD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,2BAA2B,CAAA;IACpC,CAAC;CACF;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\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, checkUserHasRole } from '@things-factory/auth-base'\n\nconst debug = require('debug')('things-factory:integration-base:operato-connector')\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache', //'network-only'\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nexport const GRAPHQL_URI = '/graphql'\nexport const SUBSCRIPTION_URI = GRAPHQL_URI\n\ninterface SubscriberData {\n tag: string\n scenario: any\n subscriptionObserver: any\n}\n\nexport class OperatoConnector implements Connector {\n private context: any\n\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('operato-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint: uri,\n params: { authKey, domain, subscriptionHandlers = {} }\n } = connection\n\n if (!authKey || !domain) {\n throw new Error('some connection paramter missing.')\n }\n\n const domainOwner = await getRepository(User).findOne({\n where: {\n id: connection.domain.owner\n }\n })\n\n this.context = {\n domain: connection.domain,\n user: domainOwner\n /* TODO: domainOwner 대신 특정 유저를 지정할 수 있도록 개선해야함. 모든 커넥션에 유저를 지정하는 기능으로 일반화할 필요가 있는 지 고민해야함 */\n }\n\n const httpLink = createHttpLink({\n uri: uri\n })\n\n /* \n CHECKPOINT: \n 1. GraphqQLWsLink를 사용하면 setContext를 통한 추가 헤더 설정이 무시됩니다.\n 따라서, GraphQLWsLink를 사용하려면, connectionParams를 통해 헤더를 설정해야 합니다.\n \n 2. 서버에서 실행시, webSocketImpl을 명시적으로 지정해야 합니다.\n */\n const wsLink = new GraphQLWsLink(\n createClient({\n url: uri.replace(/^http/, 'ws'),\n keepAlive: 10_000,\n retryAttempts: 1_000_000,\n shouldRetry: e => true,\n webSocketImpl: WebSocket,\n connectionParams: {\n headers: {\n 'x-things-factory-domain': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n })\n )\n\n const splitLink = split(\n ({ query }) => {\n const def = getMainDefinition(query)\n return def.kind === 'OperationDefinition' && def.operation === 'subscription'\n },\n wsLink,\n setContext((_, { headers }) => {\n return {\n headers: {\n ...headers,\n 'x-things-factory-domain': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n }).concat(httpLink)\n )\n\n const cache = new InMemoryCache({\n addTypename: false\n })\n\n const client = new ApolloClient({\n defaultOptions,\n cache,\n link: splitLink\n })\n\n const subscriptions: SubscriberData[] = []\n Object.keys(subscriptionHandlers).forEach(async tag => {\n if (!tag || !subscriptionHandlers[tag]) return\n\n const scenarioName = subscriptionHandlers[tag]\n\n // fetch a scenario\n const selectedScenario = await getRepository(Scenario).findOne({\n where: {\n name: scenarioName\n },\n relations: ['steps', 'domain']\n })\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n data(tag: \"${tag}\") {\n tag\n data\n }\n }\n `\n })\n\n const subscriptionObserver = subscription.subscribe({\n next: async data => {\n debug('received pubsub msg.:', data?.data)\n await this.runScenario(subscriptions, data?.data?.data)\n },\n error: error => {\n ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error`, error)\n },\n complete: () => {\n ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`)\n }\n })\n\n ConnectionManager.logger.info(\n `(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`\n )\n\n subscriptions.push({\n tag,\n scenario: selectedScenario,\n subscriptionObserver\n })\n ConnectionManager.logger.info(`(${tag}:${scenarioName}) subscription closed flag: ${subscriptionObserver.closed}`)\n })\n\n client['subscriptions'] = subscriptions\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(\n `operato-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection: InputConnection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n const subscriptions: SubscriberData[] = client['subscriptions']\n subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())\n client.stop()\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`)\n }\n\n async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {\n const { domain, user } = 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 checkUserHasRole(scenario.roleId, domain, user))) {\n throw new Error(`Unauthorized! ${scenario.name} doesn't have required role.`)\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 useDomainAttribute: true\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"]}
|
@@ -9,6 +9,7 @@ export declare class OracleConnector implements Connector {
|
|
9
9
|
type: string;
|
10
10
|
name: string;
|
11
11
|
label: string;
|
12
|
+
useDomainAttribute: boolean;
|
12
13
|
placeholder?: undefined;
|
13
14
|
value?: undefined;
|
14
15
|
} | {
|
@@ -16,6 +17,7 @@ export declare class OracleConnector implements Connector {
|
|
16
17
|
name: string;
|
17
18
|
placeholder: string;
|
18
19
|
label: string;
|
20
|
+
useDomainAttribute?: undefined;
|
19
21
|
value?: undefined;
|
20
22
|
} | {
|
21
23
|
type: string;
|
@@ -23,6 +25,7 @@ export declare class OracleConnector implements Connector {
|
|
23
25
|
placeholder: string;
|
24
26
|
label: string;
|
25
27
|
value: number;
|
28
|
+
useDomainAttribute?: undefined;
|
26
29
|
})[];
|
27
30
|
get taskPrefixes(): string[];
|
28
31
|
get help(): string;
|
@@ -135,12 +135,14 @@ class OracleConnector {
|
|
135
135
|
{
|
136
136
|
type: 'string',
|
137
137
|
name: 'user',
|
138
|
-
label: 'user'
|
138
|
+
label: 'user',
|
139
|
+
useDomainAttribute: true
|
139
140
|
},
|
140
141
|
{
|
141
142
|
type: 'password',
|
142
143
|
name: 'password',
|
143
|
-
label: 'password'
|
144
|
+
label: 'password',
|
145
|
+
useDomainAttribute: true
|
144
146
|
},
|
145
147
|
{
|
146
148
|
type: 'string',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"oracle-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/oracle-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACpC,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;AACrD,CAAC;AAED,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAEtD,s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,UAAU;gBACjB,KAAK,EAAE,CAAC;aACT;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,8BAA8B;gBAC3C,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE,CAAC;aACT;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,eAAe;gBACrB,WAAW,EAAE,6BAA6B;gBAC1C,KAAK,EAAE,gBAAgB;gBACvB,KAAK,EAAE,CAAC;aACT;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC/B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,wCAAwC,CAAA;IACjD,CAAC;CACF;AArMD,0CAqMC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,IAAI,eAAe,EAAE,CAAC,CAAA;AAE9E,kBAAkB;AAClB,yHAAyH;AACzH,4DAA4D;AAE5D,2DAA2D","sourcesContent":["import { logger } from '@things-factory/env'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var oracledb = require('oracledb')\n} catch (err) {\n logger.error('oracledb module loading failed', err)\n}\n\nexport class OracleConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('oracle-connector connections are ready')\n }\n\n async recreatePool(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n await oracledb.getPool(poolAlias).close(10)\n await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`)\n }\n\n async connect(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n\n var enableStatistics = true\n const pool = await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias,\n enableStatistics\n })\n\n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n dbConnection = await oracledb.getConnection(poolAlias)\n\n taskResult = (\n await dbConnection.execute(query, params, {\n outFormat: oracledb.OBJECT\n })\n ).rows\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n } finally {\n await dbConnection.close()\n }\n return taskResult\n },\n execute: async (procedure, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n // TODO: need to check if this is available when procedure string is a common query.\n procedure = `BEGIN\n ${procedure}\n END;`\n dbConnection = await oracledb.getConnection(poolAlias)\n\n // console.log('\\n************* stat after get ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n\n const result = await dbConnection.execute(procedure, params, {\n outFormat: oracledb.OBJECT\n })\n\n let paramKeys = Object.keys(params)\n\n for (const paramKey of paramKeys) {\n if (params[paramKey].dir === oracledb?.BIND_OUT) {\n if (params[paramKey].type === oracledb?.CURSOR) {\n const resultSetTemp = result.outBinds[paramKey]\n taskResult[paramKey] = await resultSetTemp.getRows()\n await resultSetTemp.close()\n } else {\n taskResult[paramKey] = result.outBinds[paramKey]\n }\n }\n }\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n } finally {\n await dbConnection.close()\n\n // console.log('\\n************* stat after close ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n }\n return taskResult\n },\n close: async () => {\n await oracledb.getPool(poolAlias).close(10)\n }\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`)\n }\n\n async disconnect(connection: InputConnection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n\n try {\n await client.close()\n ConnectionManager.logger.info(`Oracle Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user'\n },\n {\n type: 'password',\n name: 'password',\n label: 'password'\n },\n {\n type: 'string',\n name: 'database',\n placeholder: 'SID',\n label: 'database'\n },\n {\n type: 'number',\n name: 'poolMin',\n placeholder: 'minimum connection-pool size',\n label: 'pool-min',\n value: 0\n },\n {\n type: 'number',\n name: 'poolMax',\n placeholder: 'maximum connection-pool size',\n label: 'pool-max',\n value: 4\n },\n {\n type: 'number',\n name: 'poolIncrement',\n placeholder: 'connection incremental size',\n label: 'pool-increment',\n value: 1\n }\n ]\n }\n\n get taskPrefixes() {\n return ['database', 'oracle']\n }\n\n get help() {\n return 'integration/connector/oracle-connector'\n }\n}\n\nConnectionManager.registerConnector('oracle-connector', new OracleConnector())\n\n// need reference:\n// https://download.oracle.com/otn_software/mac/instantclient/193000/instantclient-basiclite-macos.x64-19.3.0.0.0dbru.zip\n// https://node-oracledb.readthedocs.io/en/latest/index.html\n\n// docker pull store/oracle/database-instantclient:12.2.0.1\n"]}
|
1
|
+
{"version":3,"file":"oracle-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/oracle-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACpC,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CA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AAE,UAAU;gBAChB,KAAK,EAAE,UAAU;gBACjB,kBAAkB,EAAE,IAAI;aACzB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,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;AAvMD,0CAuMC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,IAAI,eAAe,EAAE,CAAC,CAAA;AAE9E,kBAAkB;AAClB,yHAAyH;AACzH,4DAA4D;AAE5D,2DAA2D","sourcesContent":["import { logger } from '@things-factory/env'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var oracledb = require('oracledb')\n} catch (err) {\n logger.error('oracledb module loading failed', err)\n}\n\nexport class OracleConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('oracle-connector connections are ready')\n }\n\n async recreatePool(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n await oracledb.getPool(poolAlias).close(10)\n await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`)\n }\n\n async connect(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n\n var enableStatistics = true\n const pool = await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias,\n enableStatistics\n })\n\n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n dbConnection = await oracledb.getConnection(poolAlias)\n\n taskResult = (\n await dbConnection.execute(query, params, {\n outFormat: oracledb.OBJECT\n })\n ).rows\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n } finally {\n await dbConnection.close()\n }\n return taskResult\n },\n execute: async (procedure, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n // TODO: need to check if this is available when procedure string is a common query.\n procedure = `BEGIN\n ${procedure}\n END;`\n dbConnection = await oracledb.getConnection(poolAlias)\n\n // console.log('\\n************* stat after get ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n\n const result = await dbConnection.execute(procedure, params, {\n outFormat: oracledb.OBJECT\n })\n\n let paramKeys = Object.keys(params)\n\n for (const paramKey of paramKeys) {\n if (params[paramKey].dir === oracledb?.BIND_OUT) {\n if (params[paramKey].type === oracledb?.CURSOR) {\n const resultSetTemp = result.outBinds[paramKey]\n taskResult[paramKey] = await resultSetTemp.getRows()\n await resultSetTemp.close()\n } else {\n taskResult[paramKey] = result.outBinds[paramKey]\n }\n }\n }\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n } finally {\n await dbConnection.close()\n\n // console.log('\\n************* stat after close ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n }\n return taskResult\n },\n close: async () => {\n await oracledb.getPool(poolAlias).close(10)\n }\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`)\n }\n\n async disconnect(connection: InputConnection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n\n try {\n await client.close()\n ConnectionManager.logger.info(`Oracle Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user',\n useDomainAttribute: true\n },\n {\n type: 'password',\n name: 'password',\n label: 'password',\n useDomainAttribute: true\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"]}
|
@@ -8,12 +8,23 @@ export declare class PostgresqlConnector implements Connector {
|
|
8
8
|
type: string;
|
9
9
|
name: string;
|
10
10
|
label: string;
|
11
|
-
|
11
|
+
description: string;
|
12
|
+
useDomainAttribute: boolean;
|
13
|
+
placeholder?: undefined;
|
12
14
|
} | {
|
13
15
|
type: string;
|
14
16
|
name: string;
|
15
17
|
label: string;
|
16
|
-
|
18
|
+
description: string;
|
19
|
+
useDomainAttribute?: undefined;
|
20
|
+
placeholder?: undefined;
|
21
|
+
} | {
|
22
|
+
type: string;
|
23
|
+
name: string;
|
24
|
+
label: string;
|
25
|
+
description: string;
|
26
|
+
placeholder: string;
|
27
|
+
useDomainAttribute?: undefined;
|
17
28
|
})[];
|
18
29
|
get taskPrefixes(): string[];
|
19
30
|
get help(): string;
|
@@ -93,34 +93,42 @@ class PostgresqlConnector {
|
|
93
93
|
{
|
94
94
|
type: 'string',
|
95
95
|
name: 'user',
|
96
|
-
label: 'user'
|
96
|
+
label: 'user',
|
97
|
+
description: 'Database username',
|
98
|
+
useDomainAttribute: true
|
97
99
|
},
|
98
100
|
{
|
99
101
|
type: 'password',
|
100
102
|
name: 'password',
|
101
|
-
label: 'password'
|
103
|
+
label: 'password',
|
104
|
+
description: 'Database password',
|
105
|
+
useDomainAttribute: true // 🔐 Domain attributes 사용
|
102
106
|
},
|
103
107
|
{
|
104
108
|
type: 'string',
|
105
109
|
name: 'database',
|
106
|
-
label: 'database'
|
110
|
+
label: 'database',
|
111
|
+
description: 'Database name'
|
107
112
|
},
|
108
113
|
{
|
109
114
|
type: 'number',
|
110
115
|
name: 'maxPoolConnection',
|
111
|
-
label: 'maxPoolConnection'
|
116
|
+
label: 'maxPoolConnection',
|
117
|
+
description: 'Maximum pool connections'
|
112
118
|
},
|
113
119
|
{
|
114
120
|
type: 'number',
|
115
121
|
name: 'idleTimeoutMillis',
|
116
122
|
label: 'idleTimeoutMillis',
|
117
|
-
|
123
|
+
description: 'Idle timeout in milliseconds',
|
124
|
+
placeholder: 'milli-seconds'
|
118
125
|
},
|
119
126
|
{
|
120
127
|
type: 'number',
|
121
128
|
name: 'connectionTimeoutMillis',
|
122
129
|
label: 'connectionTimeoutMillis',
|
123
|
-
|
130
|
+
description: 'Connection timeout in milliseconds',
|
131
|
+
placeholder: 'milli-seconds'
|
124
132
|
}
|
125
133
|
];
|
126
134
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"postgresql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/postgresql-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,EAAE,MAAM,EAAE,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/C,IAAI,CAAC,IAAI,EAAE,CAA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;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;
|
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/C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,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mB,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 description: 'Database username',\n useDomainAttribute: true\n },\n {\n type: 'password',\n name: 'password',\n label: 'password',\n description: 'Database password',\n useDomainAttribute: true // 🔐 Domain attributes 사용\n },\n {\n type: 'string',\n name: 'database',\n label: 'database',\n description: 'Database name'\n },\n {\n type: 'number',\n name: 'maxPoolConnection',\n label: 'maxPoolConnection',\n description: 'Maximum pool connections'\n },\n {\n type: 'number',\n name: 'idleTimeoutMillis',\n label: 'idleTimeoutMillis',\n description: 'Idle timeout in milliseconds',\n placeholder: 'milli-seconds'\n },\n {\n type: 'number',\n name: 'connectionTimeoutMillis',\n label: 'connectionTimeoutMillis',\n description: 'Connection timeout in milliseconds',\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"]}
|
@@ -36,9 +36,9 @@ class PyrunConnector {
|
|
36
36
|
}
|
37
37
|
get parameterSpec() {
|
38
38
|
return [
|
39
|
-
{ type: 'string', name: 'username', label: 'username', required: false },
|
40
|
-
{ type: 'password', name: 'password', label: 'password', required: false },
|
41
|
-
{ type: 'string', name: 'token', label: 'token', required: false }
|
39
|
+
{ type: 'string', name: 'username', label: 'username', required: false, useDomainAttribute: true },
|
40
|
+
{ type: 'password', name: 'password', label: 'password', required: false, useDomainAttribute: true },
|
41
|
+
{ type: 'string', name: 'token', label: 'token', required: false, useDomainAttribute: true }
|
42
42
|
];
|
43
43
|
}
|
44
44
|
get taskPr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QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE;SAC7F,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,yCAAyC,CAAA;IAClD,CAAC;IAED,IAAI,IAAI;QACN,OAAO,uCAAuC,CAAA;IAChD,CAAC;CACF;AAzDD,wCAyDC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,iBAAiB,EAAE,IAAI,cAAc,EAAE,CAAC,CAAA","sourcesContent":["import { Connector } from '../types'\nimport { ConnectionManager } from '../connection-manager'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nexport class PyrunConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n ConnectionManager.logger.info('pyrun-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n var { username, password, token } = connection.params\n\n if (!token && username && password) {\n // /auth/login 엔드포인트로 로그인하여 토큰 발급 시도\n const loginUrl = `${connection.endpoint}/auth/login`\n const res = await fetch(loginUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ username, password })\n })\n if (!res.ok) {\n const error = await res.text()\n throw new Error(`pyrun-connector 인증 실패: ${res.status} ${error}`)\n }\n\n var data = await res.json()\n token = data.access_token\n }\n\n ConnectionManager.addConnectionInstance(connection, {\n ...connection,\n token\n })\n ConnectionManager.logger.info(`pyrun-connector connection(${connection.name}:${connection.endpoint}) is connected`)\n }\n\n async disconnect(connection: InputConnection) {\n ConnectionManager.removeConnectionInstance(connection)\n ConnectionManager.logger.info(`pyrun-connector connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return [\n { type: 'string', name: 'username', label: 'username', required: false, useDomainAttribute: true },\n { type: 'password', name: 'password', label: 'password', required: false, useDomainAttribute: true },\n { type: 'string', name: 'token', label: 'token', required: false, useDomainAttribute: true }\n ]\n }\n\n get taskPrefixes() {\n return ['pyrun']\n }\n\n get description() {\n return 'Python Runner(pyrun) REST API Connector'\n }\n\n get help() {\n return 'integration/connector/pyrun-connector'\n }\n}\n\nConnectionManager.registerConnector('pyrun-connector', new PyrunConnector())\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"edge-client.js","sourceRoot":"","sources":["../../server/engine/edge-client.ts"],"names":[],"mappings":";;AA0BA,0BAEC;AAED,0CAEC;AAED,gDAEC;AAED,sDAEC;AAED,sCAEC;AAjCD,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;AAEM,KAAK,UAAU,eAAe,CAAC,WAAyB,EAAE,OAAyB;IACxF,OAAO,MAAM,UAAU,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AAC/D,CAAC;AAEM,KAAK,UAAU,kBAAkB,CAAC,WAAyB,EAAE,OAAyB;IAC3F,OAAO,MAAM,UAAU,CAAC,kBAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AAClE,CAAC;AAEM,KAAK,UAAU,qBAAqB,CAAC,WAAyB,EAAE,OAAyB;IAC9F,OAAO,MAAM,UAAU,CAAC,qBAAqB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AACrE,CAAC;AAED,SAAgB,aAAa,CAAC,IAAgB;IAC5C,UAAU,GAAG,IAAI,CAAA;AACnB,CAAC","sourcesContent":["import { Connection } from '../service/connection/connection
|
1
|
+
{"version":3,"file":"edge-client.js","sourceRoot":"","sources":["../../server/engine/edge-client.ts"],"names":[],"mappings":";;AA0BA,0BAEC;AAED,0CAEC;AAED,gDAEC;AAED,sDAEC;AAED,sCAEC;AAjCD,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;AAEM,KAAK,UAAU,eAAe,CAAC,WAAyB,EAAE,OAAyB;IACxF,OAAO,MAAM,UAAU,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AAC/D,CAAC;AAEM,KAAK,UAAU,kBAAkB,CAAC,WAAyB,EAAE,OAAyB;IAC3F,OAAO,MAAM,UAAU,CAAC,kBAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AAClE,CAAC;AAEM,KAAK,UAAU,qBAAqB,CAAC,WAAyB,EAAE,OAAyB;IAC9F,OAAO,MAAM,UAAU,CAAC,qBAAqB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AACrE,CAAC;AAED,SAAgB,aAAa,CAAC,IAAgB;IAC5C,UAAU,GAAG,IAAI,CAAA;AACnB,CAAC","sourcesContent":["import { Connection } from '../service/connection/connection'\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"]}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { Connection,
|
1
|
+
import { Connection, ConnectionStatus } from './connection';
|
2
|
+
import { ConnectionPatch, NewConnection } from './connection-type';
|
2
3
|
export declare class ConnectionMutation {
|
3
4
|
createConnection(connection: NewConnection, context: ResolverContext): Promise<Connection>;
|
4
5
|
updateConnection(name: string, patch: ConnectionPatch, context: ResolverContext): Promise<Connection>;
|
@@ -6,11 +6,12 @@ const type_graphql_1 = require("type-graphql");
|
|
6
6
|
const typeorm_1 = require("typeorm");
|
7
7
|
const shell_1 = require("@things-factory/shell");
|
8
8
|
const connection_manager_1 = require("../../engine/connection-manager");
|
9
|
+
const connection_1 = require("./connection");
|
9
10
|
const connection_type_1 = require("./connection-type");
|
10
11
|
let ConnectionMutation = class ConnectionMutation {
|
11
12
|
async createConnection(connection, context) {
|
12
13
|
const { domain, user, tx } = context.state;
|
13
|
-
return await tx.getRepository(
|
14
|
+
return await tx.getRepository(connection_1.Connection).save({
|
14
15
|
...connection,
|
15
16
|
domain,
|
16
17
|
creator: user,
|
@@ -19,7 +20,7 @@ let ConnectionMutation = class ConnectionMutation {
|
|
19
20
|
}
|
20
21
|
async updateConnection(name, patch, context) {
|
21
22
|
const { domain, user, tx } = context.state;
|
22
|
-
const repository = tx.getRepository(
|
23
|
+
const repository = tx.getRepository(connection_1.Connection);
|
23
24
|
const connection = await repository.findOne({
|
24
25
|
where: { domain: { id: domain.id }, name }
|
25
26
|
});
|
@@ -34,7 +35,7 @@ let ConnectionMutation = class ConnectionMutation {
|
|
34
35
|
let results = [];
|
35
36
|
const _createRecords = patches.filter((patch) => patch.cuFlag.toUpperCase() === '+');
|
36
37
|
const _updateRecords = patches.filter((patch) => patch.cuFlag.toUpperCase() === 'M');
|
37
|
-
const connectionRepo = tx.getRepository(
|
38
|
+
const connectionRepo = tx.getRepository(connection_1.Connection);
|
38
39
|
if (_createRecords.length > 0) {
|
39
40
|
for (let i = 0; i < _createRecords.length; i++) {
|
40
41
|
const newRecord = _createRecords[i];
|
@@ -63,12 +64,12 @@ let ConnectionMutation = class ConnectionMutation {
|
|
63
64
|
}
|
64
65
|
async deleteConnection(name, context) {
|
65
66
|
const { domain, tx } = context.state;
|
66
|
-
await tx.getRepository(
|
67
|
+
await tx.getRepository(connection_1.Connection).delete({ domain: { id: domain.id }, name });
|
67
68
|
return true;
|
68
69
|
}
|
69
70
|
async deleteConnections(names, context) {
|
70
71
|
const { domain, tx } = context.state;
|
71
|
-
await tx.getRepository(
|
72
|
+
await tx.getRepository(connection_1.Connection).delete({
|
72
73
|
domain: { id: domain.id },
|
73
74
|
name: (0, typeorm_1.In)(names)
|
74
75
|
});
|
@@ -76,7 +77,7 @@ let ConnectionMutation = class ConnectionMutation {
|
|
76
77
|
}
|
77
78
|
async connectConnection(name, context) {
|
78
79
|
const { domain } = context.state;
|
79
|
-
var repository = (0, shell_1.getRepository)(
|
80
|
+
var repository = (0, shell_1.getRepository)(connection_1.Connection);
|
80
81
|
var connection = await repository.findOne({
|
81
82
|
where: { domain: { id: domain.id }, name },
|
82
83
|
relations: ['domain', 'edge']
|
@@ -86,13 +87,13 @@ let ConnectionMutation = class ConnectionMutation {
|
|
86
87
|
return {
|
87
88
|
...connection,
|
88
89
|
state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
|
89
|
-
?
|
90
|
-
:
|
90
|
+
? connection_1.ConnectionStatus.CONNECTED
|
91
|
+
: connection_1.ConnectionStatus.DISCONNECTED
|
91
92
|
};
|
92
93
|
}
|
93
94
|
async disconnectConnection(name, context) {
|
94
95
|
const { domain } = context.state;
|
95
|
-
var repository = (0, shell_1.getRepository)(
|
96
|
+
var repository = (0, shell_1.getRepository)(connection_1.Connection);
|
96
97
|
var connection = await repository.findOne({
|
97
98
|
where: { domain: { id: domain.id }, name },
|
98
99
|
relations: ['domain', 'edge']
|
@@ -102,13 +103,13 @@ let ConnectionMutation = class ConnectionMutation {
|
|
102
103
|
return {
|
103
104
|
...connection,
|
104
105
|
state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
|
105
|
-
?
|
106
|
-
:
|
106
|
+
? connection_1.ConnectionStatus.CONNECTED
|
107
|
+
: connection_1.ConnectionStatus.DISCONNECTED
|
107
108
|
};
|
108
109
|
}
|
109
110
|
async importConnections(connections, context) {
|
110
111
|
const { tx, domain, user } = context.state;
|
111
|
-
const repository = tx.getRepository(
|
112
|
+
const repository = tx.getRepository(connection_1.Connection);
|
112
113
|
await Promise.all(connections.map(async (connection) => {
|
113
114
|
const { id, name } = connection;
|
114
115
|
if (id) {
|
@@ -144,7 +145,7 @@ exports.ConnectionMutation = ConnectionMutation;
|
|
144
145
|
tslib_1.__decorate([
|
145
146
|
(0, type_graphql_1.Directive)('@transaction'),
|
146
147
|
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
147
|
-
(0, type_graphql_1.Mutation)(returns =>
|
148
|
+
(0, type_graphql_1.Mutation)(returns => connection_1.Connection, { description: 'Creates a new connection.' }),
|
148
149
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('connection')),
|
149
150
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
150
151
|
tslib_1.__metadata("design:type", Function),
|
@@ -154,7 +155,7 @@ tslib_1.__decorate([
|
|
154
155
|
tslib_1.__decorate([
|
155
156
|
(0, type_graphql_1.Directive)('@transaction'),
|
156
157
|
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
157
|
-
(0, type_graphql_1.Mutation)(returns =>
|
158
|
+
(0, type_graphql_1.Mutation)(returns => connection_1.Connection, { description: 'Updates an existing connection.' }),
|
158
159
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
159
160
|
tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
|
160
161
|
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
@@ -165,7 +166,7 @@ tslib_1.__decorate([
|
|
165
166
|
tslib_1.__decorate([
|
166
167
|
(0, type_graphql_1.Directive)('@transaction'),
|
167
168
|
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
168
|
-
(0, type_graphql_1.Mutation)(returns => [
|
169
|
+
(0, type_graphql_1.Mutation)(returns => [connection_1.Connection], { description: 'Updates multiple connections at once.' }),
|
169
170
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [connection_type_1.ConnectionPatch])),
|
170
171
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
171
172
|
tslib_1.__metadata("design:type", Function),
|
@@ -195,7 +196,7 @@ tslib_1.__decorate([
|
|
195
196
|
tslib_1.__decorate([
|
196
197
|
(0, type_graphql_1.Directive)('@transaction'),
|
197
198
|
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
198
|
-
(0, type_graphql_1.Mutation)(returns =>
|
199
|
+
(0, type_graphql_1.Mutation)(returns => connection_1.Connection, { description: 'Establishes a live connection to a configured endpoint.' }),
|
199
200
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
200
201
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
201
202
|
tslib_1.__metadata("design:type", Function),
|
@@ -205,7 +206,7 @@ tslib_1.__decorate([
|
|
205
206
|
tslib_1.__decorate([
|
206
207
|
(0, type_graphql_1.Directive)('@transaction'),
|
207
208
|
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
208
|
-
(0, type_graphql_1.Mutation)(returns =>
|
209
|
+
(0, type_graphql_1.Mutation)(returns => connection_1.Connection, { description: 'Terminates a live connection.' }),
|
209
210
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
210
211
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
211
212
|
tslib_1.__metadata("design:type", Function),
|
@@ -225,6 +226,6 @@ tslib_1.__decorate([
|
|
225
226
|
tslib_1.__metadata("design:returntype", Promise)
|
226
227
|
], ConnectionMutation.prototype, "importConnections", null);
|
227
228
|
exports.ConnectionMutation = ConnectionMutation = tslib_1.__decorate([
|
228
|
-
(0, type_graphql_1.Resolver)(
|
229
|
+
(0, type_graphql_1.Resolver)(connection_1.Connection)
|
229
230
|
], ConnectionMutation);
|
230
231
|
//# sourceMappingURL=connection-mutation.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"connection-mutation.js","sourceRoot":"","sources":["../../../server/service/connection/connection-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AAErD,wEAAmE;AACnE,uDAAgG;AAGzF,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAMvB,AAAN,KAAK,CAAC,gBAAgB,CACD,UAAyB,EACrC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,4BAAU,CAAC,CAAC,IAAI,CAAC;YAC7C,GAAG,UAAU;YACb,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC;IAOK,AAAN,KAAK,CAAC,gBAAgB,CACP,IAAY,EACX,KAAsB,EAC7B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,4BAAU,CAAC,CAAA;QAC/C,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC1C,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE;SAC3C,CAAC,CAAA;QAEF,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC;YAC3B,GAAG,UAAU;YACb,GAAG,KAAK;YACR,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC;IAOK,AAAN,KAAK,CAAC,wBAAwB,CACe,OAA0B,EAC9D,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA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IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,kBAAkB,CAmO9B","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionPatch, ConnectionStatus, NewConnection } from './connection-type'\n\n@Resolver(Connection)\nexport class ConnectionMutation {\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Creates a new connection.' })\n async createConnection(\n @Arg('connection') connection: NewConnection,\n @Ctx() context: ResolverContext\n ): Promise<Connection> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Connection).save({\n ...connection,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Updates an existing connection.' })\n async updateConnection(\n @Arg('name') name: string,\n @Arg('patch') patch: ConnectionPatch,\n @Ctx() context: ResolverContext\n ): Promise<Connection> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Connection)\n const connection = await repository.findOne({\n where: { domain: { id: domain.id }, name }\n })\n\n return await repository.save({\n ...connection,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => [Connection], { description: 'Updates multiple connections at once.' })\n async updateMultipleConnection(\n @Arg('patches', type => [ConnectionPatch]) patches: ConnectionPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Connection[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const connectionRepo = tx.getRepository(Connection)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await connectionRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const connection = await connectionRepo.findOneBy({ id: newRecord.id })\n\n const result = await connectionRepo.save({\n ...connection,\n ...newRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, { description: 'Deletes a single connection by its name.' })\n async deleteConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Connection).delete({ domain: { id: domain.id }, name })\n return true\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, { description: 'Deletes multiple connections by their names.' })\n async deleteConnections(\n @Arg('names', type => [String]) names: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Connection).delete({\n domain: { id: domain.id },\n name: In(names)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Establishes a live connection to a configured endpoint.' })\n async connectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain } = context.state\n var repository = getRepository(Connection)\n var connection = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain', 'edge']\n })\n\n await connection.connect()\n await repository.save(connection)\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Terminates a live connection.' })\n async disconnectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext) {\n const { domain } = context.state\n\n var repository = getRepository(Connection)\n var connection = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain', 'edge']\n })\n\n await connection.disconnect()\n await repository.save(connection)\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n }\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, {\n description: 'Imports multiple connections. Can overwrite existing connections if IDs or names match.'\n })\n async importConnections(\n @Arg('connections', type => [ConnectionPatch]) connections: Connection[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { tx, domain, user } = context.state\n\n const repository = tx.getRepository(Connection)\n\n await Promise.all(\n connections.map(async (connection: Connection) => {\n const { id, name } = connection\n\n if (id) {\n const sameId = await repository.findOneBy({ id })\n\n if (sameId) {\n if (sameId.domainId != domain.id) {\n throw `Connection with id '${id}:${name}' is already taken by another domain`\n }\n\n const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })\n if (sameName && sameName.id != id) {\n throw `Connection with name '${name}' is already taken by another connection`\n }\n\n await repository.save({\n ...sameId,\n ...connection,\n domain,\n updater: user\n })\n\n return\n }\n }\n\n await repository.save({\n ...connection,\n domain,\n updater: user,\n creator: user\n })\n })\n )\n\n return true\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"connection-mutation.js","sourceRoot":"","sources":["../../../server/service/connection/connection-mut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Mutation, Resolver } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionStatus } from './connection'\nimport { ConnectionPatch, NewConnection } from './connection-type'\n\n@Resolver(Connection)\nexport class ConnectionMutation {\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Creates a new connection.' })\n async createConnection(\n @Arg('connection') connection: NewConnection,\n @Ctx() context: ResolverContext\n ): Promise<Connection> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Connection).save({\n ...connection,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Updates an existing connection.' })\n async updateConnection(\n @Arg('name') name: string,\n @Arg('patch') patch: ConnectionPatch,\n @Ctx() context: ResolverContext\n ): Promise<Connection> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Connection)\n const connection = await repository.findOne({\n where: { domain: { id: domain.id }, name }\n })\n\n return await repository.save({\n ...connection,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => [Connection], { description: 'Updates multiple connections at once.' })\n async updateMultipleConnection(\n @Arg('patches', type => [ConnectionPatch]) patches: ConnectionPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Connection[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const connectionRepo = tx.getRepository(Connection)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await connectionRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const connection = await connectionRepo.findOneBy({ id: newRecord.id })\n\n const result = await connectionRepo.save({\n ...connection,\n ...newRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, { description: 'Deletes a single connection by its name.' })\n async deleteConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Connection).delete({ domain: { id: domain.id }, name })\n return true\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, { description: 'Deletes multiple connections by their names.' })\n async deleteConnections(\n @Arg('names', type => [String]) names: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Connection).delete({\n domain: { id: domain.id },\n name: In(names)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Establishes a live connection to a configured endpoint.' })\n async connectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain } = context.state\n var repository = getRepository(Connection)\n var connection = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain', 'edge']\n })\n\n await connection.connect()\n await repository.save(connection)\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Terminates a live connection.' })\n async disconnectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext) {\n const { domain } = context.state\n\n var repository = getRepository(Connection)\n var connection = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain', 'edge']\n })\n\n await connection.disconnect()\n await repository.save(connection)\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n }\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, {\n description: 'Imports multiple connections. Can overwrite existing connections if IDs or names match.'\n })\n async importConnections(\n @Arg('connections', type => [ConnectionPatch]) connections: Connection[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { tx, domain, user } = context.state\n\n const repository = tx.getRepository(Connection)\n\n await Promise.all(\n connections.map(async (connection: Connection) => {\n const { id, name } = connection\n\n if (id) {\n const sameId = await repository.findOneBy({ id })\n\n if (sameId) {\n if (sameId.domainId != domain.id) {\n throw `Connection with id '${id}:${name}' is already taken by another domain`\n }\n\n const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })\n if (sameName && sameName.id != id) {\n throw `Connection with name '${name}' is already taken by another connection`\n }\n\n await repository.save({\n ...sameId,\n ...connection,\n domain,\n updater: user\n })\n\n return\n }\n }\n\n await repository.save({\n ...connection,\n domain,\n updater: user,\n creator: user\n })\n })\n )\n\n return true\n }\n}\n"]}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { Appliance, User } from '@things-factory/auth-base';
|
2
2
|
import { Domain, ListParam } from '@things-factory/shell';
|
3
|
-
import { Connection
|
3
|
+
import { Connection } from './connection';
|
4
|
+
import { ConnectionList, ConnectionState } from './connection-type';
|
4
5
|
/**
|
5
6
|
* @description Provides GraphQL resolvers for the Connection entity.
|
6
7
|
*/
|