@things-factory/integration-base 8.0.5 → 9.0.0-beta.12
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/connector/headless-connector.d.ts +23 -0
- package/dist-server/engine/connector/headless-connector.js +357 -0
- package/dist-server/engine/connector/headless-connector.js.map +1 -0
- package/dist-server/engine/connector/http-connector.js +1 -1
- package/dist-server/engine/connector/http-connector.js.map +1 -1
- package/dist-server/engine/connector/index.d.ts +1 -0
- package/dist-server/engine/connector/index.js +1 -0
- package/dist-server/engine/connector/index.js.map +1 -1
- package/dist-server/engine/index.d.ts +1 -0
- package/dist-server/engine/index.js +1 -0
- package/dist-server/engine/index.js.map +1 -1
- package/dist-server/engine/resource-pool/headless-pool.d.ts +1 -0
- package/dist-server/engine/resource-pool/headless-pool.js +62 -0
- package/dist-server/engine/resource-pool/headless-pool.js.map +1 -0
- package/dist-server/engine/resource-pool/index.d.ts +1 -0
- package/dist-server/engine/resource-pool/index.js +5 -0
- package/dist-server/engine/resource-pool/index.js.map +1 -0
- package/dist-server/engine/task/headless-post.js +19 -33
- package/dist-server/engine/task/headless-post.js.map +1 -1
- package/dist-server/engine/task/headless-scrap.js +20 -13
- package/dist-server/engine/task/headless-scrap.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -11
- package/translations/en.json +12 -4
- package/translations/ja.json +12 -4
- package/translations/ko.json +12 -4
- package/translations/ms.json +12 -4
- package/translations/zh.json +12 -4
- package/server/controllers/index.ts +0 -2
- package/server/controllers/publish-data.ts +0 -29
- package/server/controllers/scenario-controller.ts +0 -154
- package/server/engine/analyzer/analyze-integration.ts +0 -115
- package/server/engine/connection-manager.ts +0 -239
- package/server/engine/connector/echo-back-connector.ts +0 -51
- package/server/engine/connector/echo-back-server.ts +0 -72
- package/server/engine/connector/graphql-connector.ts +0 -126
- package/server/engine/connector/http-connector.ts +0 -65
- package/server/engine/connector/index.ts +0 -12
- package/server/engine/connector/mqtt-connector.ts +0 -78
- package/server/engine/connector/mssql-connector.ts +0 -152
- package/server/engine/connector/mysql-connector.ts +0 -94
- package/server/engine/connector/operato-connector.ts +0 -264
- package/server/engine/connector/oracle-connector.ts +0 -218
- package/server/engine/connector/postgresql-connector.ts +0 -152
- package/server/engine/connector/proxy-connector.ts +0 -53
- package/server/engine/connector/socket-server.ts +0 -86
- package/server/engine/connector/sqlite-connector.ts +0 -69
- package/server/engine/edge-client.ts +0 -45
- package/server/engine/index.ts +0 -10
- package/server/engine/pending-queue.ts +0 -97
- package/server/engine/scenario-engine.ts +0 -106
- package/server/engine/task/book-up-scenario.ts +0 -73
- package/server/engine/task/csv-readline.ts +0 -127
- package/server/engine/task/data-accessor.ts +0 -36
- package/server/engine/task/data-mapper.ts +0 -47
- package/server/engine/task/database-query.ts +0 -56
- package/server/engine/task/echo-receive.ts +0 -21
- package/server/engine/task/echo-send.ts +0 -32
- package/server/engine/task/empty-check.ts +0 -38
- package/server/engine/task/end.ts +0 -18
- package/server/engine/task/floating-point.ts +0 -71
- package/server/engine/task/goto.ts +0 -27
- package/server/engine/task/graphql-mutate.ts +0 -79
- package/server/engine/task/graphql-query.ts +0 -78
- package/server/engine/task/headless-post.ts +0 -147
- package/server/engine/task/headless-scrap.ts +0 -80
- package/server/engine/task/http-get.ts +0 -117
- package/server/engine/task/http-post.ts +0 -148
- package/server/engine/task/index.ts +0 -45
- package/server/engine/task/jsonata.ts +0 -45
- package/server/engine/task/local-graphql-mutate.ts +0 -100
- package/server/engine/task/local-graphql-query.ts +0 -100
- package/server/engine/task/log.ts +0 -78
- package/server/engine/task/mqtt-publish.ts +0 -45
- package/server/engine/task/mqtt-subscribe.ts +0 -139
- package/server/engine/task/mssql-procedure.ts +0 -128
- package/server/engine/task/oracle-procedure.ts +0 -124
- package/server/engine/task/pick-pending-scenario.ts +0 -80
- package/server/engine/task/publish.ts +0 -40
- package/server/engine/task/random.ts +0 -53
- package/server/engine/task/reset-pending-queue.ts +0 -17
- package/server/engine/task/script.ts +0 -63
- package/server/engine/task/set-domain.ts +0 -37
- package/server/engine/task/sleep.ts +0 -34
- package/server/engine/task/socket-listener.ts +0 -96
- package/server/engine/task/state-group-read.ts +0 -69
- package/server/engine/task/state-read.ts +0 -56
- package/server/engine/task/state-write.ts +0 -65
- package/server/engine/task/stop-scenario.ts +0 -44
- package/server/engine/task/sub-scenario.ts +0 -57
- package/server/engine/task/switch-goto.ts +0 -43
- package/server/engine/task/switch-range-goto.ts +0 -53
- package/server/engine/task/switch-range-scenario.ts +0 -79
- package/server/engine/task/switch-range-set.ts +0 -48
- package/server/engine/task/switch-scenario.ts +0 -67
- package/server/engine/task/switch-set.ts +0 -37
- package/server/engine/task/throw.ts +0 -27
- package/server/engine/task/utils/headless-pool-for-scenario.ts +0 -71
- package/server/engine/task/utils/substitute.ts +0 -44
- package/server/engine/task/variables.ts +0 -17
- package/server/engine/task-registry.ts +0 -23
- package/server/engine/types.ts +0 -114
- package/server/index.ts +0 -20
- package/server/migrations/index.ts +0 -9
- package/server/restful/index.ts +0 -1
- package/server/restful/unstable/index.ts +0 -7
- package/server/restful/unstable/run-scenario.ts +0 -51
- package/server/restful/unstable/scenario-instance.ts +0 -52
- package/server/restful/unstable/scenario-instances.ts +0 -80
- package/server/restful/unstable/scenario.ts +0 -41
- package/server/restful/unstable/scenarios.ts +0 -69
- package/server/restful/unstable/start-scenario.ts +0 -33
- package/server/restful/unstable/stop-scenario.ts +0 -30
- package/server/routers/scenario-schedule-callback-router.ts +0 -69
- package/server/routers/scenario-view-router.ts +0 -46
- package/server/routes.ts +0 -30
- package/server/service/analysis/analysis-query.ts +0 -13
- package/server/service/analysis/index.ts +0 -3
- package/server/service/connection/connection-mutation.ts +0 -190
- package/server/service/connection/connection-query.ts +0 -87
- package/server/service/connection/connection-subscription.ts +0 -104
- package/server/service/connection/connection-type.ts +0 -288
- package/server/service/connection/index.ts +0 -7
- package/server/service/connector/connector-query.ts +0 -62
- package/server/service/connector/connector-type.ts +0 -29
- package/server/service/connector/index.ts +0 -4
- package/server/service/index.ts +0 -52
- package/server/service/payload-log/index.ts +0 -7
- package/server/service/payload-log/payload-log-mutation.ts +0 -151
- package/server/service/payload-log/payload-log-query.ts +0 -49
- package/server/service/payload-log/payload-log-type.ts +0 -36
- package/server/service/payload-log/payload-log.ts +0 -100
- package/server/service/property-spec.ts +0 -24
- package/server/service/scenario/index.ts +0 -6
- package/server/service/scenario/scenario-mutation.ts +0 -396
- package/server/service/scenario/scenario-query.ts +0 -109
- package/server/service/scenario/scenario-type.ts +0 -78
- package/server/service/scenario/scenario.ts +0 -124
- package/server/service/scenario-flow/scenario-flow.ts +0 -17
- package/server/service/scenario-instance/index.ts +0 -6
- package/server/service/scenario-instance/scenario-instance-mutation.ts +0 -44
- package/server/service/scenario-instance/scenario-instance-query.ts +0 -42
- package/server/service/scenario-instance/scenario-instance-subscription.ts +0 -118
- package/server/service/scenario-instance/scenario-instance-type.ts +0 -563
- package/server/service/scenario-queue/index.ts +0 -4
- package/server/service/scenario-queue/scenario-queue-subscription.ts +0 -55
- package/server/service/scenario-queue/scenario-queue-type.ts +0 -27
- package/server/service/state-register/data-resolver.ts +0 -56
- package/server/service/state-register/index.ts +0 -8
- package/server/service/state-register/state-register-mutation.ts +0 -166
- package/server/service/state-register/state-register-query.ts +0 -80
- package/server/service/state-register/state-register-type.ts +0 -80
- package/server/service/state-register/state-register.ts +0 -113
- package/server/service/step/index.ts +0 -6
- package/server/service/step/step-mutation.ts +0 -52
- package/server/service/step/step-query.ts +0 -55
- package/server/service/step/step-type.ts +0 -215
- package/server/service/task-type/index.ts +0 -4
- package/server/service/task-type/task-type-query.ts +0 -95
- package/server/service/task-type/task-type-type.ts +0 -29
@@ -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,30 +0,0 @@
|
|
1
|
-
import { config } from '@things-factory/env'
|
2
|
-
|
3
|
-
import { scenarioViewRouter } from './routers/scenario-view-router'
|
4
|
-
import { scenarioScheduleCallbackRouter } from './routers/scenario-schedule-callback-router'
|
5
|
-
|
6
|
-
const isPathBaseDomain = !config.get('subdomain') && !config.get('useVirtualHostBasedDomain')
|
7
|
-
|
8
|
-
process.on('bootstrap-module-domain-public-route' as any, (app, domainPrivateRouter) => {
|
9
|
-
if (isPathBaseDomain) {
|
10
|
-
domainPrivateRouter.use(
|
11
|
-
'/domain/:domain',
|
12
|
-
scenarioScheduleCallbackRouter.routes(),
|
13
|
-
scenarioScheduleCallbackRouter.allowedMethods()
|
14
|
-
)
|
15
|
-
} else {
|
16
|
-
domainPrivateRouter.use(
|
17
|
-
'',
|
18
|
-
scenarioScheduleCallbackRouter.routes(),
|
19
|
-
scenarioScheduleCallbackRouter.allowedMethods()
|
20
|
-
)
|
21
|
-
}
|
22
|
-
})
|
23
|
-
|
24
|
-
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
25
|
-
if (isPathBaseDomain) {
|
26
|
-
domainPrivateRouter.use('/domain/:domain', scenarioViewRouter.routes(), scenarioViewRouter.allowedMethods())
|
27
|
-
} else {
|
28
|
-
domainPrivateRouter.use('', scenarioViewRouter.routes(), scenarioViewRouter.allowedMethods())
|
29
|
-
}
|
30
|
-
})
|
@@ -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,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
|
-
}
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
2
|
-
|
3
|
-
import { Appliance, User } from '@things-factory/auth-base'
|
4
|
-
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
5
|
-
|
6
|
-
import { ConnectionManager } from '../../engine/connection-manager'
|
7
|
-
import { Connection, ConnectionList, ConnectionState, ConnectionStatus } from './connection-type'
|
8
|
-
|
9
|
-
@Resolver(Connection)
|
10
|
-
export class ConnectionQuery {
|
11
|
-
@Query(returns => Connection, { description: 'To fetch a connection' })
|
12
|
-
async connection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {
|
13
|
-
const { domain } = context.state
|
14
|
-
|
15
|
-
var connection = await getRepository(Connection).findOne({
|
16
|
-
where: { domain: { id: domain.id }, name },
|
17
|
-
relations: ['domain']
|
18
|
-
})
|
19
|
-
|
20
|
-
return {
|
21
|
-
...connection,
|
22
|
-
state: ConnectionManager.getConnectionInstance(connection)
|
23
|
-
? ConnectionStatus.CONNECTED
|
24
|
-
: ConnectionStatus.DISCONNECTED
|
25
|
-
} as Connection
|
26
|
-
}
|
27
|
-
|
28
|
-
@Query(returns => ConnectionList, { description: 'To fetch multiple connections' })
|
29
|
-
async connections(
|
30
|
-
@Args(type => ListParam) params: ListParam,
|
31
|
-
@Ctx() context: ResolverContext
|
32
|
-
): Promise<ConnectionList> {
|
33
|
-
const { domain } = context.state
|
34
|
-
|
35
|
-
const queryBuilder = getQueryBuilderFromListParams({
|
36
|
-
repository: getRepository(Connection),
|
37
|
-
params,
|
38
|
-
domain,
|
39
|
-
alias: 'connection',
|
40
|
-
searchables: ['name', 'description', 'type', 'endpoint']
|
41
|
-
})
|
42
|
-
|
43
|
-
const [items, total] = await queryBuilder.leftJoinAndSelect('connection.domain', 'domain').getManyAndCount()
|
44
|
-
|
45
|
-
items.forEach(connection => {
|
46
|
-
connection['state'] = ConnectionManager.getConnectionInstance(connection)
|
47
|
-
? ConnectionStatus.CONNECTED
|
48
|
-
: ConnectionStatus.DISCONNECTED
|
49
|
-
})
|
50
|
-
|
51
|
-
return { items, total }
|
52
|
-
}
|
53
|
-
|
54
|
-
@Query(returns => ConnectionState, { description: 'To fetch the state of a connection' })
|
55
|
-
fetchConnectionState(@Arg('name') name: string, @Ctx() context: ResolverContext): ConnectionState {
|
56
|
-
const { domain } = context.state
|
57
|
-
|
58
|
-
const connection = ConnectionManager.getConnectionInstanceEntityByName(domain, name)
|
59
|
-
|
60
|
-
return {
|
61
|
-
...connection,
|
62
|
-
state: connection ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
@FieldResolver(type => Domain)
|
67
|
-
async edge(@Root() connection: Connection) {
|
68
|
-
return connection.edgeId && (await getRepository(Appliance).findOneBy({ id: connection.edgeId }))
|
69
|
-
}
|
70
|
-
|
71
|
-
@FieldResolver(type => Domain)
|
72
|
-
async domain(@Root() connection: Connection) {
|
73
|
-
return (
|
74
|
-
connection.domain || (connection.domainId && (await getRepository(Domain).findOneBy({ id: connection.domainId })))
|
75
|
-
)
|
76
|
-
}
|
77
|
-
|
78
|
-
@FieldResolver(type => User)
|
79
|
-
async updater(@Root() connection: Connection): Promise<User> {
|
80
|
-
return connection.updaterId && (await getRepository(User).findOneBy({ id: connection.updaterId }))
|
81
|
-
}
|
82
|
-
|
83
|
-
@FieldResolver(type => User)
|
84
|
-
async creator(@Root() connection: Connection): Promise<User> {
|
85
|
-
return connection.creatorId && (await getRepository(User).findOneBy({ id: connection.creatorId }))
|
86
|
-
}
|
87
|
-
}
|
@@ -1,104 +0,0 @@
|
|
1
|
-
import { filter, pipe } from 'graphql-yoga'
|
2
|
-
import { Arg, Resolver, Root, Subscription } from 'type-graphql'
|
3
|
-
|
4
|
-
import { getRepository, Log, pubsub } from '@things-factory/shell'
|
5
|
-
|
6
|
-
import { ConnectionManager } from '../../engine/connection-manager'
|
7
|
-
import { Connection, ConnectionState, ConnectionStatus } from './connection-type'
|
8
|
-
|
9
|
-
const debug = require('debug')('things-factory:integration:connection-subscription')
|
10
|
-
|
11
|
-
@Resolver(Connection)
|
12
|
-
export class ConnectionSubscription {
|
13
|
-
@Subscription({
|
14
|
-
subscribe: ({ args, context, info }) => {
|
15
|
-
const { domain, user } = context.state
|
16
|
-
const { name } = args
|
17
|
-
const subdomain = domain?.subdomain
|
18
|
-
|
19
|
-
debug('subscribe', subdomain)
|
20
|
-
if (!domain) {
|
21
|
-
throw new Error('domain required.')
|
22
|
-
}
|
23
|
-
|
24
|
-
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
25
|
-
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
|
26
|
-
}
|
27
|
-
|
28
|
-
process.nextTick(async () => {
|
29
|
-
var where = { domain: { id: domain.id } }
|
30
|
-
if (name) {
|
31
|
-
where['name'] = name
|
32
|
-
}
|
33
|
-
|
34
|
-
var connections = await getRepository(Connection).find({
|
35
|
-
where,
|
36
|
-
relations: ['domain', 'edge']
|
37
|
-
})
|
38
|
-
|
39
|
-
connections.forEach(connection => {
|
40
|
-
pubsub.publish('connection-state', {
|
41
|
-
connectionState: {
|
42
|
-
...connection,
|
43
|
-
state: ConnectionManager.getConnectionInstance(connection) ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED,
|
44
|
-
timestamp: new Date()
|
45
|
-
}
|
46
|
-
})
|
47
|
-
})
|
48
|
-
})
|
49
|
-
|
50
|
-
return pipe(
|
51
|
-
pubsub.subscribe('connection-state'),
|
52
|
-
filter(async (payload: { connectionState: ConnectionState }) => {
|
53
|
-
const { domain: pdomain, name: pname } = payload.connectionState
|
54
|
-
|
55
|
-
return (!name || name === pname) && subdomain === pdomain?.subdomain
|
56
|
-
})
|
57
|
-
)
|
58
|
-
}
|
59
|
-
})
|
60
|
-
connectionState(@Root() payload: { connectionState: ConnectionState }, @Arg('name', { nullable: true }) name: string): ConnectionState {
|
61
|
-
return payload.connectionState
|
62
|
-
}
|
63
|
-
|
64
|
-
@Subscription({
|
65
|
-
subscribe: ({ args, context, info }) => {
|
66
|
-
const { domain, user } = context.state
|
67
|
-
const { level } = args
|
68
|
-
|
69
|
-
const subdomain = domain?.subdomain
|
70
|
-
|
71
|
-
debug('subscribe', subdomain)
|
72
|
-
|
73
|
-
if (!domain) {
|
74
|
-
throw new Error('domain required')
|
75
|
-
}
|
76
|
-
|
77
|
-
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
78
|
-
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
|
79
|
-
}
|
80
|
-
|
81
|
-
return pipe(
|
82
|
-
pubsub.subscribe('connection-log'),
|
83
|
-
filter(async (payload: { log: Log }) => {
|
84
|
-
// TODO support domain filtering
|
85
|
-
const { /* source, */ level: plevel } = payload.log
|
86
|
-
// const { domain: pdomain } = source
|
87
|
-
|
88
|
-
// if (subdomain !== pdomain?.subdomain) {
|
89
|
-
// return false
|
90
|
-
// }
|
91
|
-
|
92
|
-
if (level && level !== plevel) {
|
93
|
-
return false
|
94
|
-
}
|
95
|
-
|
96
|
-
return true
|
97
|
-
})
|
98
|
-
)
|
99
|
-
}
|
100
|
-
})
|
101
|
-
connectionLog(@Root() payload: { log: Log }, @Arg('level', { nullable: true }) level: string): Log {
|
102
|
-
return payload.log
|
103
|
-
}
|
104
|
-
}
|