@things-factory/integration-base 8.0.40 → 9.0.0-9.0.0-beta.59.0

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 (169) hide show
  1. package/dist-server/engine/connector/headless-connector.d.ts +23 -0
  2. package/dist-server/engine/connector/headless-connector.js +357 -0
  3. package/dist-server/engine/connector/headless-connector.js.map +1 -0
  4. package/dist-server/engine/connector/http-connector.js +1 -1
  5. package/dist-server/engine/connector/http-connector.js.map +1 -1
  6. package/dist-server/engine/connector/index.d.ts +1 -0
  7. package/dist-server/engine/connector/index.js +1 -0
  8. package/dist-server/engine/connector/index.js.map +1 -1
  9. package/dist-server/engine/index.d.ts +3 -2
  10. package/dist-server/engine/index.js +3 -2
  11. package/dist-server/engine/index.js.map +1 -1
  12. package/dist-server/engine/resource-pool/headless-pool.d.ts +1 -0
  13. package/dist-server/engine/resource-pool/headless-pool.js +62 -0
  14. package/dist-server/engine/resource-pool/headless-pool.js.map +1 -0
  15. package/dist-server/engine/resource-pool/index.d.ts +1 -0
  16. package/dist-server/engine/resource-pool/index.js +5 -0
  17. package/dist-server/engine/resource-pool/index.js.map +1 -0
  18. package/dist-server/engine/task/headless-post.js +19 -33
  19. package/dist-server/engine/task/headless-post.js.map +1 -1
  20. package/dist-server/engine/task/headless-scrap.js +20 -13
  21. package/dist-server/engine/task/headless-scrap.js.map +1 -1
  22. package/dist-server/index.d.ts +6 -6
  23. package/dist-server/index.js +10 -10
  24. package/dist-server/index.js.map +1 -1
  25. package/dist-server/routes.js +6 -6
  26. package/dist-server/routes.js.map +1 -1
  27. package/dist-server/service/connection/connection-mutation.js +17 -5
  28. package/dist-server/service/connection/connection-mutation.js.map +1 -1
  29. package/dist-server/service/connection/connection-query.js +3 -0
  30. package/dist-server/service/connection/connection-query.js.map +1 -1
  31. package/dist-server/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +12 -11
  33. package/translations/en.json +12 -4
  34. package/translations/ja.json +12 -4
  35. package/translations/ko.json +12 -4
  36. package/translations/ms.json +12 -4
  37. package/translations/zh.json +12 -4
  38. package/server/controllers/index.ts +0 -2
  39. package/server/controllers/publish-data.ts +0 -29
  40. package/server/controllers/scenario-controller.ts +0 -154
  41. package/server/engine/analyzer/analyze-integration.ts +0 -115
  42. package/server/engine/connection-manager.ts +0 -232
  43. package/server/engine/connector/echo-back-connector.ts +0 -51
  44. package/server/engine/connector/echo-back-server.ts +0 -72
  45. package/server/engine/connector/graphql-connector.ts +0 -126
  46. package/server/engine/connector/http-connector.ts +0 -65
  47. package/server/engine/connector/index.ts +0 -12
  48. package/server/engine/connector/mqtt-connector.ts +0 -78
  49. package/server/engine/connector/mssql-connector.ts +0 -152
  50. package/server/engine/connector/mysql-connector.ts +0 -94
  51. package/server/engine/connector/operato-connector.ts +0 -264
  52. package/server/engine/connector/oracle-connector.ts +0 -218
  53. package/server/engine/connector/postgresql-connector.ts +0 -152
  54. package/server/engine/connector/proxy-connector.ts +0 -53
  55. package/server/engine/connector/socket-server.ts +0 -86
  56. package/server/engine/connector/sqlite-connector.ts +0 -69
  57. package/server/engine/edge-client.ts +0 -45
  58. package/server/engine/index.ts +0 -10
  59. package/server/engine/pending-queue.ts +0 -97
  60. package/server/engine/scenario-engine.ts +0 -106
  61. package/server/engine/task/book-up-scenario.ts +0 -73
  62. package/server/engine/task/csv-readline.ts +0 -127
  63. package/server/engine/task/data-accessor.ts +0 -36
  64. package/server/engine/task/data-mapper.ts +0 -47
  65. package/server/engine/task/database-query.ts +0 -56
  66. package/server/engine/task/echo-receive.ts +0 -21
  67. package/server/engine/task/echo-send.ts +0 -32
  68. package/server/engine/task/empty-check.ts +0 -38
  69. package/server/engine/task/end.ts +0 -18
  70. package/server/engine/task/floating-point.ts +0 -71
  71. package/server/engine/task/goto.ts +0 -27
  72. package/server/engine/task/graphql-mutate.ts +0 -79
  73. package/server/engine/task/graphql-query.ts +0 -78
  74. package/server/engine/task/headless-post.ts +0 -147
  75. package/server/engine/task/headless-scrap.ts +0 -80
  76. package/server/engine/task/http-get.ts +0 -117
  77. package/server/engine/task/http-post.ts +0 -148
  78. package/server/engine/task/index.ts +0 -45
  79. package/server/engine/task/jsonata.ts +0 -45
  80. package/server/engine/task/local-graphql-mutate.ts +0 -100
  81. package/server/engine/task/local-graphql-query.ts +0 -100
  82. package/server/engine/task/log.ts +0 -78
  83. package/server/engine/task/mqtt-publish.ts +0 -69
  84. package/server/engine/task/mqtt-subscribe.ts +0 -291
  85. package/server/engine/task/mssql-procedure.ts +0 -128
  86. package/server/engine/task/oracle-procedure.ts +0 -124
  87. package/server/engine/task/pick-pending-scenario.ts +0 -80
  88. package/server/engine/task/publish.ts +0 -40
  89. package/server/engine/task/random.ts +0 -53
  90. package/server/engine/task/reset-pending-queue.ts +0 -17
  91. package/server/engine/task/script.ts +0 -63
  92. package/server/engine/task/set-domain.ts +0 -37
  93. package/server/engine/task/sleep.ts +0 -34
  94. package/server/engine/task/socket-listener.ts +0 -96
  95. package/server/engine/task/state-group-read.ts +0 -69
  96. package/server/engine/task/state-read.ts +0 -56
  97. package/server/engine/task/state-write.ts +0 -65
  98. package/server/engine/task/stop-scenario.ts +0 -44
  99. package/server/engine/task/sub-scenario.ts +0 -57
  100. package/server/engine/task/switch-goto.ts +0 -43
  101. package/server/engine/task/switch-range-goto.ts +0 -53
  102. package/server/engine/task/switch-range-scenario.ts +0 -79
  103. package/server/engine/task/switch-range-set.ts +0 -48
  104. package/server/engine/task/switch-scenario.ts +0 -67
  105. package/server/engine/task/switch-set.ts +0 -37
  106. package/server/engine/task/throw.ts +0 -27
  107. package/server/engine/task/utils/headless-pool-for-scenario.ts +0 -71
  108. package/server/engine/task/utils/substitute.ts +0 -44
  109. package/server/engine/task/variables.ts +0 -17
  110. package/server/engine/task-registry.ts +0 -23
  111. package/server/engine/types.ts +0 -114
  112. package/server/index.ts +0 -20
  113. package/server/migrations/index.ts +0 -9
  114. package/server/restful/index.ts +0 -1
  115. package/server/restful/unstable/index.ts +0 -7
  116. package/server/restful/unstable/run-scenario.ts +0 -51
  117. package/server/restful/unstable/scenario-instance.ts +0 -52
  118. package/server/restful/unstable/scenario-instances.ts +0 -80
  119. package/server/restful/unstable/scenario.ts +0 -41
  120. package/server/restful/unstable/scenarios.ts +0 -69
  121. package/server/restful/unstable/start-scenario.ts +0 -33
  122. package/server/restful/unstable/stop-scenario.ts +0 -30
  123. package/server/routers/scenario-schedule-callback-router.ts +0 -69
  124. package/server/routers/scenario-view-router.ts +0 -46
  125. package/server/routes.ts +0 -35
  126. package/server/service/analysis/analysis-query.ts +0 -13
  127. package/server/service/analysis/index.ts +0 -3
  128. package/server/service/connection/connection-mutation.ts +0 -190
  129. package/server/service/connection/connection-query.ts +0 -87
  130. package/server/service/connection/connection-subscription.ts +0 -104
  131. package/server/service/connection/connection-type.ts +0 -305
  132. package/server/service/connection/index.ts +0 -7
  133. package/server/service/connector/connector-query.ts +0 -62
  134. package/server/service/connector/connector-type.ts +0 -29
  135. package/server/service/connector/index.ts +0 -4
  136. package/server/service/index.ts +0 -52
  137. package/server/service/payload-log/index.ts +0 -7
  138. package/server/service/payload-log/payload-log-mutation.ts +0 -151
  139. package/server/service/payload-log/payload-log-query.ts +0 -49
  140. package/server/service/payload-log/payload-log-type.ts +0 -36
  141. package/server/service/payload-log/payload-log.ts +0 -100
  142. package/server/service/property-spec.ts +0 -24
  143. package/server/service/scenario/index.ts +0 -6
  144. package/server/service/scenario/scenario-mutation.ts +0 -396
  145. package/server/service/scenario/scenario-query.ts +0 -109
  146. package/server/service/scenario/scenario-type.ts +0 -78
  147. package/server/service/scenario/scenario.ts +0 -124
  148. package/server/service/scenario-flow/scenario-flow.ts +0 -17
  149. package/server/service/scenario-instance/index.ts +0 -6
  150. package/server/service/scenario-instance/scenario-instance-mutation.ts +0 -44
  151. package/server/service/scenario-instance/scenario-instance-query.ts +0 -42
  152. package/server/service/scenario-instance/scenario-instance-subscription.ts +0 -118
  153. package/server/service/scenario-instance/scenario-instance-type.ts +0 -557
  154. package/server/service/scenario-queue/index.ts +0 -4
  155. package/server/service/scenario-queue/scenario-queue-subscription.ts +0 -55
  156. package/server/service/scenario-queue/scenario-queue-type.ts +0 -27
  157. package/server/service/state-register/data-resolver.ts +0 -56
  158. package/server/service/state-register/index.ts +0 -8
  159. package/server/service/state-register/state-register-mutation.ts +0 -166
  160. package/server/service/state-register/state-register-query.ts +0 -80
  161. package/server/service/state-register/state-register-type.ts +0 -80
  162. package/server/service/state-register/state-register.ts +0 -113
  163. package/server/service/step/index.ts +0 -6
  164. package/server/service/step/step-mutation.ts +0 -52
  165. package/server/service/step/step-query.ts +0 -55
  166. package/server/service/step/step-type.ts +0 -238
  167. package/server/service/task-type/index.ts +0 -4
  168. package/server/service/task-type/task-type-query.ts +0 -95
  169. package/server/service/task-type/task-type-type.ts +0 -29
@@ -1,80 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { restfulApiRouter as router } from '@things-factory/api'
3
-
4
- const debug = require('debug')('things-factory:integration-base:restful:unstable:scenario-instances')
5
-
6
- function FPSparams(query) {
7
- var { page, limit } = query
8
-
9
- var filters = []
10
- var sortings = []
11
-
12
- page = parseInt(page)
13
- limit = parseInt(limit)
14
-
15
- var pagination = {
16
- page: isNaN(page) ? 0 : page,
17
- limit: isNaN(limit) ? 100 : limit
18
- }
19
-
20
- return {
21
- filters,
22
- sortings,
23
- pagination
24
- }
25
- }
26
-
27
- router.get('/unstable/scenario-instances', async (context, next) => {
28
- const { client } = context.state
29
-
30
- var { filters, sortings, pagination } = FPSparams(context.query)
31
-
32
- debug('get:/unstable/scenario-instances', context.params)
33
-
34
- context.body = await client.query({
35
- query: gql`
36
- query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
37
- scenarioInstances(filters: $filters, pagination: $pagination, sortings: $sortings) {
38
- items {
39
- root {
40
- instanceName
41
- scenarioName
42
- state
43
- progress {
44
- rounds
45
- rate
46
- steps
47
- step
48
- }
49
- variables
50
- data
51
- message
52
- timestamp
53
- }
54
- instanceName
55
- scenarioName
56
- state
57
- progress {
58
- rounds
59
- rate
60
- steps
61
- step
62
- }
63
- variables
64
- data
65
- message
66
- timestamp
67
- }
68
-
69
- total
70
- }
71
- }
72
- `,
73
- variables: {
74
- filters,
75
- pagination,
76
- sortings
77
- },
78
- context
79
- })
80
- })
@@ -1,41 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { restfulApiRouter as router } from '@things-factory/api'
3
-
4
- const debug = require('debug')('things-factory:integration-base:restful:unstable:scenario')
5
-
6
- router.get('/unstable/scenario/:id', async (context, next) => {
7
- const { client } = context.state
8
- const { id } = context.params
9
-
10
- debug('get:/unstable/scenario/:id', context.params)
11
-
12
- context.body = await client.query({
13
- query: gql`
14
- query ($id: String!) {
15
- scenario(id: $id) {
16
- id
17
- name
18
- description
19
- state
20
- schedule
21
- timezone
22
- steps {
23
- id
24
- name
25
- description
26
- sequence
27
- task
28
- skip
29
- log
30
- connection
31
- params
32
- }
33
- }
34
- }
35
- `,
36
- variables: {
37
- id
38
- },
39
- context
40
- })
41
- })
@@ -1,69 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { restfulApiRouter as router } from '@things-factory/api'
3
-
4
- const debug = require('debug')('things-factory:integration-base:restful:unstable:scenarios')
5
-
6
- function FPSparams(query) {
7
- var { page, limit } = query
8
-
9
- var filters = []
10
- var sortings = []
11
-
12
- page = parseInt(page)
13
- limit = parseInt(limit)
14
-
15
- var pagination = {
16
- page: isNaN(page) ? 0 : page,
17
- limit: isNaN(limit) ? 100 : limit
18
- }
19
-
20
- return {
21
- filters,
22
- sortings,
23
- pagination
24
- }
25
- }
26
-
27
- router.get('/unstable/scenarios', async (context, next) => {
28
- const { client } = context.state
29
-
30
- var { filters, sortings, pagination } = FPSparams(context.query)
31
-
32
- debug('get:/unstable/scenarios', context.params)
33
-
34
- context.body = await client.query({
35
- query: gql`
36
- query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
37
- scenarios(filters: $filters, pagination: $pagination, sortings: $sortings) {
38
- items {
39
- id
40
- name
41
- description
42
- active
43
- state
44
- schedule
45
- timezone
46
- steps {
47
- id
48
- name
49
- description
50
- sequence
51
- task
52
- skip
53
- log
54
- connection
55
- params
56
- }
57
- }
58
- total
59
- }
60
- }
61
- `,
62
- variables: {
63
- filters,
64
- pagination,
65
- sortings
66
- },
67
- context
68
- })
69
- })
@@ -1,33 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { restfulApiRouter as router } from '@things-factory/api'
3
-
4
- const debug = require('debug')('things-factory:integration-base:restful:unstable:start-scenario')
5
-
6
- router.post('/unstable/start-scenario/:scenarioName', async (context, next) => {
7
- const { client } = context.state
8
- const { scenarioName } = context.params
9
- const { instanceName = '', variables = {} } = context.request.body || {}
10
-
11
- debug('post:/unstable/start-scenario/:scenarioName', scenarioName)
12
-
13
- context.body = await client.mutate({
14
- mutation: gql`
15
- mutation ($instanceName: String, $scenarioName: String!, $variables: Object) {
16
- startScenario(instanceName: $instanceName, scenarioName: $scenarioName, variables: $variables) {
17
- instanceName
18
- scenarioName
19
- state
20
- data
21
- message
22
- timestamp
23
- }
24
- }
25
- `,
26
- variables: {
27
- instanceName,
28
- scenarioName,
29
- variables
30
- },
31
- context
32
- })
33
- })
@@ -1,30 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { restfulApiRouter as router } from '@things-factory/api'
3
-
4
- const debug = require('debug')('things-factory:integration-base:restful:unstable:stop-scenario')
5
-
6
- router.post('/unstable/stop-scenario/:instanceName', async (context, next) => {
7
- const { client } = context.state
8
- const { instanceName } = context.params
9
-
10
- debug('post:/unstable/stop-scenario/:scenarioName', instanceName)
11
-
12
- context.body = await client.mutate({
13
- mutation: gql`
14
- mutation ($instanceName: String!) {
15
- stopScenario(instanceName: $instanceName) {
16
- instanceName
17
- scenarioName
18
- state
19
- data
20
- message
21
- timestamp
22
- }
23
- }
24
- `,
25
- variables: {
26
- instanceName
27
- },
28
- context
29
- })
30
- })
@@ -1,69 +0,0 @@
1
- import Router from 'koa-router'
2
-
3
- import { getRepository } from '@things-factory/shell'
4
- import { User } from '@things-factory/auth-base'
5
- import { ScheduleRegisterRequest } from '@things-factory/scheduler-client'
6
-
7
- import { Scenario } from '../service/scenario/scenario'
8
- import { ScenarioEngine } from '../engine/scenario-engine'
9
-
10
- export const scenarioScheduleCallbackRouter = new Router()
11
-
12
- /* When a callback occurs from the scheduler when a scheduled scenario is on schedule. */
13
- scenarioScheduleCallbackRouter.post('/callback-schedule-for-scenario', async (context, next) => {
14
- const { client, task } = context.request.body as ScheduleRegisterRequest
15
- const { userId } = task?.data
16
-
17
- // application: Application,
18
- // group: `${domain.id}`,
19
- // type: 'scenario',
20
- // key: scenario.id,
21
- // operation: 'start'
22
-
23
- const { domain } = context.state
24
-
25
- if (!domain) {
26
- throw new Error('cannot identify the current domain.')
27
- }
28
-
29
- if (!client || typeof client !== 'object') {
30
- throw new Error('client property should be a part of callback body.')
31
- }
32
-
33
- const { group: domainId, key: scenarioId, operation, type } = client
34
-
35
- if (!domainId || !scenarioId) {
36
- throw new Error(`group(${domainId}) and key(${scenarioId}) properties should not be empty`)
37
- }
38
-
39
- if (domainId != domain.id) {
40
- throw new Error('client property(group) is not matched with the current domain.')
41
- }
42
-
43
- if (type != 'scenario') {
44
- throw new Error('client property(type) is not matched with the required value.')
45
- }
46
-
47
- if (operation != 'start') {
48
- throw new Error('client property(operation) is not matched with the required value.')
49
- }
50
-
51
- const scenario = await getRepository(Scenario).findOne({
52
- where: { domain: { id: domainId }, id: scenarioId },
53
- relations: ['domain', 'steps', 'creator']
54
- })
55
-
56
- if (!scenario) {
57
- throw new Error(`Scenario having given scenarioId(${domain?.subdomain}:${scenarioId}) not found`)
58
- }
59
-
60
- const user = (userId && (await getRepository(User).findOne({ where: { id: userId } }))) || scenario.creator
61
-
62
- ScenarioEngine.load(scenario.name, scenario, {
63
- domain,
64
- user
65
- /* variables: schedule 등록시 variables 는 설정할 방법이 없음. */
66
- })
67
-
68
- context.status = 200
69
- })
@@ -1,46 +0,0 @@
1
- import Router from 'koa-router'
2
-
3
- import { getRepository } from '@things-factory/shell'
4
-
5
- import { Scenario } from '../service/scenario/scenario'
6
- import { Step } from '../service/step/step-type'
7
-
8
- export const scenarioViewRouter = new Router()
9
-
10
- scenarioViewRouter.get('/scenario-view/:name', async (context, next) => {
11
- const { domain } = context.state
12
- const { name } = context.params
13
-
14
- const scenario = await getRepository(Scenario).findOne({
15
- where: {
16
- domain: { id: domain.id },
17
- name
18
- },
19
- relations: ['steps']
20
- })
21
-
22
- const steps: Step[] = scenario.steps
23
- const nodes = {}
24
- const edges = []
25
-
26
- steps.forEach(({ id, name }) => {
27
- nodes[id] = {
28
- id,
29
- name
30
- }
31
- })
32
-
33
- for (let i = 0; i < steps.length - 1; i++) {
34
- edges.push({
35
- source: steps[i].id,
36
- target: steps[i + 1].id
37
- })
38
- }
39
-
40
- await context.render('scenario-view', {
41
- model: {
42
- nodes,
43
- edges
44
- }
45
- })
46
- })
package/server/routes.ts DELETED
@@ -1,35 +0,0 @@
1
- import { config } from '@things-factory/env'
2
- import { getRoutePrefixForDomainType } from '@things-factory/shell'
3
-
4
- import { scenarioViewRouter } from './routers/scenario-view-router'
5
- import { scenarioScheduleCallbackRouter } from './routers/scenario-schedule-callback-router'
6
-
7
- const isPathBaseDomain = !config.get('subdomain')
8
-
9
- process.on('bootstrap-module-domain-public-route' as any, (app, domainPrivateRouter) => {
10
- if (isPathBaseDomain) {
11
- domainPrivateRouter.use(
12
- `/${getRoutePrefixForDomainType()}/:domain`,
13
- scenarioScheduleCallbackRouter.routes(),
14
- scenarioScheduleCallbackRouter.allowedMethods()
15
- )
16
- } else {
17
- domainPrivateRouter.use(
18
- '',
19
- scenarioScheduleCallbackRouter.routes(),
20
- scenarioScheduleCallbackRouter.allowedMethods()
21
- )
22
- }
23
- })
24
-
25
- process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
26
- if (isPathBaseDomain) {
27
- domainPrivateRouter.use(
28
- `/${getRoutePrefixForDomainType()}/:domain`,
29
- scenarioViewRouter.routes(),
30
- scenarioViewRouter.allowedMethods()
31
- )
32
- } else {
33
- domainPrivateRouter.use('', scenarioViewRouter.routes(), scenarioViewRouter.allowedMethods())
34
- }
35
- })
@@ -1,13 +0,0 @@
1
- import { Resolver, Query, Ctx } from 'type-graphql'
2
- import { ScalarObject } from '@things-factory/shell'
3
- import { analyzeIntegration } from '../../engine/analyzer/analyze-integration'
4
-
5
- @Resolver()
6
- export class IntegrationAnalysisQuery {
7
- @Query(returns => ScalarObject, { description: 'To fetch integration Analyses' })
8
- async integrationAnalysis(@Ctx() context: ResolverContext): Promise<any> {
9
- const { domain } = context.state
10
-
11
- return await analyzeIntegration(domain)
12
- }
13
- }
@@ -1,3 +0,0 @@
1
- import { IntegrationAnalysisQuery } from './analysis-query'
2
-
3
- export const resolvers = [IntegrationAnalysisQuery]
@@ -1,190 +0,0 @@
1
- import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { In } from 'typeorm'
3
-
4
- import { getRepository } from '@things-factory/shell'
5
-
6
- import { ConnectionManager } from '../../engine/connection-manager'
7
- import { Connection, ConnectionPatch, ConnectionStatus, NewConnection } from './connection-type'
8
-
9
- @Resolver(Connection)
10
- export class ConnectionMutation {
11
- @Directive('@transaction')
12
- @Mutation(returns => Connection, { description: 'To create new connection' })
13
- async createConnection(@Arg('connection') connection: NewConnection, @Ctx() context: ResolverContext): Promise<Connection> {
14
- const { domain, user, tx } = context.state
15
-
16
- return await tx.getRepository(Connection).save({
17
- ...connection,
18
- domain,
19
- creator: user,
20
- updater: user
21
- })
22
- }
23
-
24
- @Directive('@transaction')
25
- @Mutation(returns => Connection, { description: 'To modify connection information' })
26
- async updateConnection(@Arg('name') name: string, @Arg('patch') patch: ConnectionPatch, @Ctx() context: ResolverContext): Promise<Connection> {
27
- const { domain, user, tx } = context.state
28
-
29
- const repository = tx.getRepository(Connection)
30
- const connection = await repository.findOne({
31
- where: { domain: { id: domain.id }, name }
32
- })
33
-
34
- return await repository.save({
35
- ...connection,
36
- ...patch,
37
- updater: user
38
- })
39
- }
40
-
41
- @Directive('@transaction')
42
- @Mutation(returns => [Connection], { description: "To modify multiple connections' information" })
43
- async updateMultipleConnection(@Arg('patches', type => [ConnectionPatch]) patches: ConnectionPatch[], @Ctx() context: ResolverContext): Promise<Connection[]> {
44
- const { domain, user, tx } = context.state
45
-
46
- let results = []
47
- const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
48
- const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
49
- const connectionRepo = tx.getRepository(Connection)
50
-
51
- if (_createRecords.length > 0) {
52
- for (let i = 0; i < _createRecords.length; i++) {
53
- const newRecord = _createRecords[i]
54
-
55
- const result = await connectionRepo.save({
56
- ...newRecord,
57
- domain,
58
- creator: user,
59
- updater: user
60
- })
61
-
62
- results.push({ ...result, cuFlag: '+' })
63
- }
64
- }
65
-
66
- if (_updateRecords.length > 0) {
67
- for (let i = 0; i < _updateRecords.length; i++) {
68
- const newRecord = _updateRecords[i]
69
- const connection = await connectionRepo.findOneBy({ id: newRecord.id })
70
-
71
- const result = await connectionRepo.save({
72
- ...connection,
73
- ...newRecord,
74
- updater: user
75
- })
76
-
77
- results.push({ ...result, cuFlag: 'M' })
78
- }
79
- }
80
-
81
- return results
82
- }
83
-
84
- @Directive('@transaction')
85
- @Mutation(returns => Boolean, { description: 'To delete connection' })
86
- async deleteConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {
87
- const { domain, tx } = context.state
88
-
89
- await tx.getRepository(Connection).delete({ domain: { id: domain.id }, name })
90
- return true
91
- }
92
-
93
- @Directive('@transaction')
94
- @Mutation(returns => Boolean, { description: 'To delete multiple connections' })
95
- async deleteConnections(@Arg('names', type => [String]) names: string[], @Ctx() context: ResolverContext): Promise<boolean> {
96
- const { domain, tx } = context.state
97
-
98
- await tx.getRepository(Connection).delete({
99
- domain: { id: domain.id },
100
- name: In(names)
101
- })
102
-
103
- return true
104
- }
105
-
106
- @Mutation(returns => Connection, { description: 'To connect a connection' })
107
- async connectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {
108
- const { domain } = context.state
109
- var repository = getRepository(Connection)
110
- var connection = await repository.findOne({
111
- where: { domain: { id: domain.id }, name },
112
- relations: ['domain', 'edge']
113
- })
114
-
115
- await connection.connect()
116
- await repository.save(connection)
117
-
118
- return {
119
- ...connection,
120
- state: ConnectionManager.getConnectionInstance(connection) ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED
121
- } as Connection
122
- }
123
-
124
- @Mutation(returns => Connection, { description: 'To disconnect a connection' })
125
- async disconnectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext) {
126
- const { domain } = context.state
127
-
128
- var repository = getRepository(Connection)
129
- var connection = await repository.findOne({
130
- where: { domain: { id: domain.id }, name },
131
- relations: ['domain', 'edge']
132
- })
133
-
134
- await connection.disconnect()
135
- await repository.save(connection)
136
-
137
- return {
138
- ...connection,
139
- state: ConnectionManager.getConnectionInstance(connection) ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED
140
- }
141
- }
142
-
143
- @Directive('@transaction')
144
- // @Directive('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true)')
145
- @Mutation(returns => Boolean, { description: 'To import multiple connections' })
146
- async importConnections(@Arg('connections', type => [ConnectionPatch]) connections: Connection[], @Ctx() context: ResolverContext): Promise<boolean> {
147
- const { tx, domain, user } = context.state
148
-
149
- const repository = tx.getRepository(Connection)
150
-
151
- await Promise.all(
152
- connections.map(async (connection: Connection) => {
153
- const { id, name } = connection
154
-
155
- if (id) {
156
- const sameId = await repository.findOneBy({ id })
157
-
158
- if (sameId) {
159
- if (sameId.domainId != domain.id) {
160
- throw `Connection with id '${id}:${name}' is already taken by another domain`
161
- }
162
-
163
- const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })
164
- if (sameName && sameName.id != id) {
165
- throw `Connection with name '${name}' is already taken by another connection`
166
- }
167
-
168
- await repository.save({
169
- ...sameId,
170
- ...connection,
171
- domain,
172
- updater: user
173
- })
174
-
175
- return
176
- }
177
- }
178
-
179
- await repository.save({
180
- ...connection,
181
- domain,
182
- updater: user,
183
- creator: user
184
- })
185
- })
186
- )
187
-
188
- return true
189
- }
190
- }