@things-factory/integration-base 8.0.37 → 8.0.39

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": "8.0.37",
3
+ "version": "8.0.39",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -27,13 +27,13 @@
27
27
  "dependencies": {
28
28
  "@apollo/client": "^3.6.9",
29
29
  "@operato/moment-timezone-es": "^8.0.0",
30
- "@things-factory/api": "^8.0.37",
31
- "@things-factory/auth-base": "^8.0.37",
32
- "@things-factory/cache-service": "^8.0.37",
30
+ "@things-factory/api": "^8.0.38",
31
+ "@things-factory/auth-base": "^8.0.38",
32
+ "@things-factory/cache-service": "^8.0.38",
33
33
  "@things-factory/env": "^8.0.37",
34
- "@things-factory/oauth2-client": "^8.0.37",
35
- "@things-factory/scheduler-client": "^8.0.37",
36
- "@things-factory/shell": "^8.0.37",
34
+ "@things-factory/oauth2-client": "^8.0.38",
35
+ "@things-factory/scheduler-client": "^8.0.38",
36
+ "@things-factory/shell": "^8.0.38",
37
37
  "@things-factory/utils": "^8.0.37",
38
38
  "async-mqtt": "^2.5.0",
39
39
  "chance": "^1.1.11",
@@ -44,5 +44,5 @@
44
44
  "readline": "^1.3.0",
45
45
  "ses": "^1.5.0"
46
46
  },
47
- "gitHead": "a3a78656259d6c5d3719ba0864d6bdde87bcba7d"
47
+ "gitHead": "f5e1a4c04bceec2d731a46f1ef88976839d04dac"
48
48
  }
@@ -76,7 +76,7 @@ export async function analyzeIntegration(domain: Domain) {
76
76
  const tags = uniq(
77
77
  scenario.steps
78
78
  .filter(step => !step.connection && step.task == 'publish')
79
- .map(step => JSON.parse(step.params)?.tag)
79
+ .map(step => step.params?.tag)
80
80
  .filter(Boolean)
81
81
  )
82
82
 
@@ -61,16 +61,9 @@ export class ConnectionManager {
61
61
  relations: ['domain', 'edge', 'creator', 'updater']
62
62
  })
63
63
  ).map(connection => {
64
- var params = {}
65
- try {
66
- params = JSON.parse(connection.params || '{}')
67
- } catch (ex) {
68
- ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format`, ex)
69
- }
70
-
71
64
  return {
72
65
  ...connection,
73
- params
66
+ params: connection.params || {}
74
67
  }
75
68
  })
76
69
 
@@ -11,12 +11,15 @@ import {
11
11
  } from 'typeorm'
12
12
 
13
13
  import { User, Appliance } from '@things-factory/auth-base'
14
- import { logger } from '@things-factory/env'
15
- import { Domain, ObjectRef } from '@things-factory/shell'
14
+ import { config } from '@things-factory/env'
15
+ import { Domain, ObjectRef, ScalarObject } from '@things-factory/shell'
16
16
 
17
17
  import { ConnectionManager } from '../../engine'
18
18
  import { ProxyConnector } from '../../engine/connector/proxy-connector'
19
19
 
20
+ const ORMCONFIG = config.get('ormconfig', {})
21
+ const DATABASE_TYPE = ORMCONFIG.type
22
+
20
23
  export enum ConnectionStatus {
21
24
  CONNECTED = 'CONNECTED',
22
25
  DISCONNECTED = 'DISCONNECTED'
@@ -109,10 +112,31 @@ export class Connection {
109
112
 
110
113
  /**
111
114
  * Additional parameters for the connection, stored as a JSON string.
115
+ *
116
+ * [Caution]
117
+ * 이 컬럼타입은 postgres 데이터베이스에서는 varchar 타입을 유지한다.
118
+ * 이는 데이터베이스 타입을 변경하면 기존 데이터가 손실될 수 있기 때문이다.
119
+ * 'simple-json' 타입으로 변경 전에 postgres 데이타베이스에 이미 varchar 타입으로 사용한 사례가 많기 때문이다.
112
120
  */
113
- @Column({ nullable: true })
114
- @Field({ nullable: true })
115
- params: string
121
+ @Column({
122
+ type: DATABASE_TYPE == 'postgres' ? 'varchar' : 'simple-json',
123
+ nullable: true,
124
+ transformer:
125
+ DATABASE_TYPE == 'postgres'
126
+ ? {
127
+ to: (value: any) => JSON.stringify(value),
128
+ from: (value: string) => {
129
+ try {
130
+ return JSON.parse(value)
131
+ } catch (error) {
132
+ return null
133
+ }
134
+ }
135
+ }
136
+ : undefined
137
+ })
138
+ @Field(type => ScalarObject, { nullable: true })
139
+ params: { [key: string]: any }
116
140
 
117
141
  /**
118
142
  * The date and time when the connection was created.
@@ -163,17 +187,10 @@ export class Connection {
163
187
  async connect() {
164
188
  const { type, edge } = this
165
189
  const connector = edge ? ProxyConnector.instance : ConnectionManager.getConnector(type)
166
- var params = {}
167
-
168
- try {
169
- params = JSON.parse(this.params || '{}')
170
- } catch (ex) {
171
- logger.error(`connection '${this.name}' params should be JSON format`, ex)
172
- }
173
190
 
174
191
  await connector.connect({
175
192
  ...this,
176
- params
193
+ params: this.params || {}
177
194
  })
178
195
  }
179
196
 
@@ -244,8 +261,8 @@ export class NewConnection {
244
261
  @Field({ nullable: true })
245
262
  endpoint?: string
246
263
 
247
- @Field({ nullable: true })
248
- params?: string
264
+ @Field(type => ScalarObject, { nullable: true })
265
+ params?: { [key: string]: any }
249
266
  }
250
267
 
251
268
  @InputType()
@@ -271,8 +288,8 @@ export class ConnectionPatch {
271
288
  @Field({ nullable: true })
272
289
  active?: boolean
273
290
 
274
- @Field({ nullable: true })
275
- params?: string
291
+ @Field(type => ScalarObject, { nullable: true })
292
+ params?: { [key: string]: any }
276
293
 
277
294
  @Field({ nullable: true })
278
295
  cuFlag?: string
@@ -84,7 +84,7 @@ export class ScenarioQuery {
84
84
  where: { domain: { id: domain.id }, scenario: { id: scenario.id }, task: 'publish' }
85
85
  })
86
86
 
87
- return steps.map(step => JSON.parse(step.params)?.tag).filter(Boolean)
87
+ return steps.map(step => step.params?.tag).filter(Boolean)
88
88
  }
89
89
 
90
90
  @FieldResolver(type => String, { nullable: true })
@@ -519,15 +519,9 @@ export class ScenarioInstance {
519
519
  this.context.logger.info(`Step '${step.name}'(${step.id}) started.`)
520
520
 
521
521
  step = {
522
- ...step
523
- } // copy step
524
-
525
- try {
526
- step.params = JSON.parse(step.params)
527
- } catch (ex) {
528
- this.context.logger.error(`params(${step.params}) parsing error. params must be a JSON.`, ex)
522
+ ...step,
523
+ params: step.params || {}
529
524
  }
530
- step.params = step.params || {}
531
525
 
532
526
  const connection =
533
527
  step.connection && ConnectionManager.getConnectionInstanceEntityByName(this.domain, step.connection)
@@ -11,10 +11,14 @@ import {
11
11
  } from 'typeorm'
12
12
 
13
13
  import { User } from '@things-factory/auth-base'
14
- import { Domain } from '@things-factory/shell'
14
+ import { Domain, ScalarObject } from '@things-factory/shell'
15
+ import { config } from '@things-factory/env'
15
16
 
16
17
  import { Scenario } from '../scenario/scenario'
17
18
 
19
+ const ORMCONFIG = config.get('ormconfig', {})
20
+ const DATABASE_TYPE = ORMCONFIG.type
21
+
18
22
  @Entity()
19
23
  @Index('ix_step_0', (step: Step) => [step.scenario, step.sequence], { unique: true })
20
24
  @ObjectType()
@@ -103,10 +107,31 @@ export class Step {
103
107
 
104
108
  /**
105
109
  * The parameters for the step.
106
- */
107
- @Column({ nullable: true })
108
- @Field({ nullable: true })
109
- params?: string
110
+ *
111
+ * [Caution]
112
+ * 컬럼타입은 postgres 데이터베이스에서는 varchar 타입을 유지한다.
113
+ * 이는 데이터베이스 타입을 변경하면 기존 데이터가 손실될 수 있기 때문이다.
114
+ * 'simple-json' 타입으로 변경 전에 postgres 데이타베이스에 이미 varchar 타입으로 사용한 사례가 많기 때문이다.
115
+ */
116
+ @Column({
117
+ type: DATABASE_TYPE == 'postgres' ? 'varchar' : 'simple-json',
118
+ nullable: true,
119
+ transformer:
120
+ DATABASE_TYPE == 'postgres'
121
+ ? {
122
+ to: (value: any) => JSON.stringify(value),
123
+ from: (value: string) => {
124
+ try {
125
+ return JSON.parse(value)
126
+ } catch (error) {
127
+ return null
128
+ }
129
+ }
130
+ }
131
+ : undefined
132
+ })
133
+ @Field(type => ScalarObject, { nullable: true })
134
+ params?: { [key: string]: any }
110
135
 
111
136
  /**
112
137
  * A boolean attribute indicating the inclusion status of an element in the result.
@@ -186,8 +211,8 @@ export class StepPatch {
186
211
  @Field({ nullable: true })
187
212
  connection?: string
188
213
 
189
- @Field({ nullable: true })
190
- params?: string
214
+ @Field(type => ScalarObject, { nullable: true })
215
+ params?: { [key: string]: any }
191
216
 
192
217
  @Field({ nullable: true })
193
218
  result?: boolean
@@ -201,9 +226,7 @@ export class StepPatch {
201
226
  * 추후, 타입 일치를 통해서 제거할 예정임.
202
227
  *
203
228
  */
204
- export interface InputStep extends Step {
205
- params: any
206
- }
229
+ export interface InputStep extends Step {}
207
230
 
208
231
  @ObjectType()
209
232
  export class StepList {