@things-factory/integration-base 6.1.101 → 6.1.103

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-base",
3
- "version": "6.1.101",
3
+ "version": "6.1.103",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -46,5 +46,5 @@
46
46
  "devDependencies": {
47
47
  "@types/cron": "^2.0.1"
48
48
  },
49
- "gitHead": "1ecb1d6fca22c20751878c234b9139ff0dac7766"
49
+ "gitHead": "c5acba2345556dd71e885ca56692c8a50216568e"
50
50
  }
@@ -0,0 +1,106 @@
1
+ import uniq from 'lodash/uniq'
2
+
3
+ import { Domain, getRepository } from '@things-factory/shell'
4
+ import { Scenario } from '../../service/scenario/scenario-type'
5
+ import { Connection } from '../../service/connection/connection-type'
6
+
7
+ export async function analyzeIntegration(domain: Domain) {
8
+ const tagNames = []
9
+
10
+ const model = {
11
+ nodes: [],
12
+ relationships: []
13
+ }
14
+
15
+ var id = 0
16
+
17
+ const scenarios = await getRepository(Scenario).find({
18
+ where: { domain: { id: domain.id } },
19
+ relations: ['steps']
20
+ })
21
+
22
+ const connections = await getRepository(Connection).find({
23
+ where: { domain: { id: domain.id } }
24
+ })
25
+
26
+ model.nodes = model.nodes.concat(
27
+ scenarios.map(scenario => {
28
+ return {
29
+ id: scenario.id,
30
+ labels: ['Scenario'],
31
+ properties: {
32
+ scenarioId: scenario.id
33
+ }
34
+ }
35
+ })
36
+ )
37
+
38
+ model.nodes = model.nodes.concat(
39
+ connections.map(connection => {
40
+ return {
41
+ id: ++id,
42
+ labels: ['Connection'],
43
+ properties: {
44
+ connectionId: connection.id
45
+ }
46
+ }
47
+ })
48
+ )
49
+
50
+ scenarios.forEach(scenario => {
51
+ const connectionNames = uniq(scenario.steps.map(step => step.connection).filter(Boolean))
52
+ const connectionList = connectionNames
53
+ .map(connectionName => connections.find(connection => connection.name == connectionName))
54
+ .filter(Boolean)
55
+
56
+ const relationships = connectionList.map(connection => {
57
+ return {
58
+ id: ++id,
59
+ type: 'using',
60
+ sourceNode: scenario.id,
61
+ targetNode: connection.id
62
+ }
63
+ })
64
+
65
+ model.relationships = model.relationships.concat(relationships)
66
+ })
67
+
68
+ scenarios.forEach(scenario => {
69
+ const tags = uniq(
70
+ scenario.steps
71
+ .filter(step => !step.connection && step.task == 'publish')
72
+ .map(step => JSON.parse(step.params)?.tag)
73
+ .filter(Boolean)
74
+ )
75
+
76
+ for (const tag of tags) {
77
+ if (tagNames.includes(tag)) {
78
+ continue
79
+ }
80
+
81
+ model.nodes.push({
82
+ id: `tag-${tag}`,
83
+ labels: ['Tag'],
84
+ properties: {
85
+ tag
86
+ }
87
+ })
88
+
89
+ tagNames.push(tag)
90
+ }
91
+
92
+ const relationships = tags.map(tag => {
93
+ return {
94
+ id: ++id,
95
+ type: 'publish',
96
+ sourceNode: scenario.id,
97
+ targetNode: `tag-${tag}`,
98
+ properties: {}
99
+ }
100
+ })
101
+
102
+ model.relationships = model.relationships.concat(relationships)
103
+ })
104
+
105
+ return model
106
+ }
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ import { IntegrationAnalysisQuery } from './analysis-query'
2
+
3
+ export const resolvers = [IntegrationAnalysisQuery]
@@ -6,6 +6,7 @@ import { entities as ScenarioQueueEntities, resolvers as ScenarioQueueResolvers
6
6
  import { entities as StepEntities, resolvers as StepResolvers } from './step'
7
7
  import { entities as TaskTypeEntities, resolvers as TaskTypeResolvers } from './task-type'
8
8
  import { entities as PayloadLogEntities, resolvers as PayloadLogResolvers } from './payload-log'
9
+ import { resolvers as IntegrationAnalysisQuery } from './analysis'
9
10
 
10
11
  export * from './property-spec'
11
12
  export * from './task-type/task-type-type'
@@ -38,9 +39,10 @@ export const schema = {
38
39
  ...ScenarioInstanceResolvers,
39
40
  ...ScenarioQueueResolvers,
40
41
  ...StepResolvers,
41
- ...PayloadLogResolvers
42
+ ...PayloadLogResolvers,
43
+ ...IntegrationAnalysisQuery
42
44
  ]
43
45
  }
44
46
 
45
47
  export { PayloadType } from './payload-log/payload-log'
46
- export { createPayloadLog } from './payload-log/payload-log-mutation'
48
+ export { createPayloadLog } from './payload-log/payload-log-mutation'
@@ -1,4 +1,5 @@
1
1
  import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
+ import { Not, IsNull } from 'typeorm'
2
3
 
3
4
  import { User } from '@things-factory/auth-base'
4
5
  import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
@@ -7,6 +8,7 @@ import { ScenarioEngine } from '../../engine'
7
8
  import { ScenarioInstance, ScenarioInstanceStatus } from '../scenario-instance/scenario-instance-type'
8
9
  import { Step } from '../step/step-type'
9
10
  import { Scenario, ScenarioList } from './scenario-type'
11
+ import { Connection } from '../connection/connection-type'
10
12
 
11
13
  @Resolver(Scenario)
12
14
  export class ScenarioQuery {
@@ -62,7 +64,27 @@ export class ScenarioQuery {
62
64
  })
63
65
  }
64
66
 
65
- /* 아래 두개 FieldResolvertype에는 정의하지 않았지만, 스키마에는 자동으로 추가되는 것으로 보인다. */
67
+ @FieldResolver(type => [Connection])
68
+ async connectionNames(@Root() scenario: Scenario, @Ctx() context: ResolverContext) {
69
+ const { domain } = context.state
70
+
71
+ const steps = await getRepository(Step).find({
72
+ where: { domain: { id: domain.id }, scenario: { id: scenario.id }, connection: Not(IsNull()) }
73
+ })
74
+
75
+ return steps.map(step => step.connection).filter(Boolean)
76
+ }
77
+
78
+ @FieldResolver(type => [Connection])
79
+ async publishTags(@Root() scenario: Scenario, @Ctx() context: ResolverContext) {
80
+ const { domain } = context.state
81
+
82
+ const steps = await getRepository(Step).find({
83
+ where: { domain: { id: domain.id }, scenario: { id: scenario.id }, task: 'publish' }
84
+ })
85
+
86
+ return steps.map(step => JSON.parse(step.params)?.tag).filter(Boolean)
87
+ }
66
88
 
67
89
  @FieldResolver(type => String, { nullable: true })
68
90
  async state(@Root() scenario: Scenario, @Ctx() context: ResolverContext): Promise<string> {