@things-factory/integration-base 9.0.20 → 9.0.25

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 (98) hide show
  1. package/dist-server/engine/analyzer/analyze-integration.js +2 -2
  2. package/dist-server/engine/analyzer/analyze-integration.js.map +1 -1
  3. package/dist-server/engine/connection-manager.d.ts +13 -1
  4. package/dist-server/engine/connection-manager.js +105 -7
  5. package/dist-server/engine/connection-manager.js.map +1 -1
  6. package/dist-server/engine/connector/headless-connector.d.ts +8 -0
  7. package/dist-server/engine/connector/headless-connector.js +4 -2
  8. package/dist-server/engine/connector/headless-connector.js.map +1 -1
  9. package/dist-server/engine/connector/mqtt-connector.d.ts +1 -0
  10. package/dist-server/engine/connector/mqtt-connector.js +4 -2
  11. package/dist-server/engine/connector/mqtt-connector.js.map +1 -1
  12. package/dist-server/engine/connector/mssql-connector.d.ts +4 -0
  13. package/dist-server/engine/connector/mssql-connector.js +4 -2
  14. package/dist-server/engine/connector/mssql-connector.js.map +1 -1
  15. package/dist-server/engine/connector/mysql-connector.d.ts +10 -2
  16. package/dist-server/engine/connector/mysql-connector.js +23 -18
  17. package/dist-server/engine/connector/mysql-connector.js.map +1 -1
  18. package/dist-server/engine/connector/operato-connector.d.ts +8 -2
  19. package/dist-server/engine/connector/operato-connector.js +2 -1
  20. package/dist-server/engine/connector/operato-connector.js.map +1 -1
  21. package/dist-server/engine/connector/oracle-connector.d.ts +3 -0
  22. package/dist-server/engine/connector/oracle-connector.js +4 -2
  23. package/dist-server/engine/connector/oracle-connector.js.map +1 -1
  24. package/dist-server/engine/connector/postgresql-connector.d.ts +13 -2
  25. package/dist-server/engine/connector/postgresql-connector.js +14 -6
  26. package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
  27. package/dist-server/engine/connector/pyrun-connector.d.ts +1 -0
  28. package/dist-server/engine/connector/pyrun-connector.js +3 -3
  29. package/dist-server/engine/connector/pyrun-connector.js.map +1 -1
  30. package/dist-server/engine/edge-client.d.ts +1 -1
  31. package/dist-server/engine/edge-client.js.map +1 -1
  32. package/dist-server/engine/task/database-query.js +1 -1
  33. package/dist-server/engine/task/database-query.js.map +1 -1
  34. package/dist-server/engine/task/echo-receive.js +1 -1
  35. package/dist-server/engine/task/echo-receive.js.map +1 -1
  36. package/dist-server/engine/task/echo-send.js +1 -1
  37. package/dist-server/engine/task/echo-send.js.map +1 -1
  38. package/dist-server/engine/task/graphql-mutate.js +1 -1
  39. package/dist-server/engine/task/graphql-mutate.js.map +1 -1
  40. package/dist-server/engine/task/graphql-query.js +1 -1
  41. package/dist-server/engine/task/graphql-query.js.map +1 -1
  42. package/dist-server/engine/task/headless-post.js +1 -1
  43. package/dist-server/engine/task/headless-post.js.map +1 -1
  44. package/dist-server/engine/task/headless-scrap.js +1 -1
  45. package/dist-server/engine/task/headless-scrap.js.map +1 -1
  46. package/dist-server/engine/task/http-get.js +1 -1
  47. package/dist-server/engine/task/http-get.js.map +1 -1
  48. package/dist-server/engine/task/http-post.js +1 -1
  49. package/dist-server/engine/task/http-post.js.map +1 -1
  50. package/dist-server/engine/task/mqtt-publish.js +1 -1
  51. package/dist-server/engine/task/mqtt-publish.js.map +1 -1
  52. package/dist-server/engine/task/mqtt-subscribe.js +1 -1
  53. package/dist-server/engine/task/mqtt-subscribe.js.map +1 -1
  54. package/dist-server/engine/task/mssql-procedure.js +1 -1
  55. package/dist-server/engine/task/mssql-procedure.js.map +1 -1
  56. package/dist-server/engine/task/oracle-procedure.js +1 -1
  57. package/dist-server/engine/task/oracle-procedure.js.map +1 -1
  58. package/dist-server/engine/task/pyrun-execute.js +1 -1
  59. package/dist-server/engine/task/pyrun-execute.js.map +1 -1
  60. package/dist-server/engine/task/socket-listener.js +1 -1
  61. package/dist-server/engine/task/socket-listener.js.map +1 -1
  62. package/dist-server/service/connection/connection-mutation.d.ts +3 -1
  63. package/dist-server/service/connection/connection-mutation.js +62 -22
  64. package/dist-server/service/connection/connection-mutation.js.map +1 -1
  65. package/dist-server/service/connection/connection-query.d.ts +2 -1
  66. package/dist-server/service/connection/connection-query.js +14 -13
  67. package/dist-server/service/connection/connection-query.js.map +1 -1
  68. package/dist-server/service/connection/connection-subscription.js +6 -4
  69. package/dist-server/service/connection/connection-subscription.js.map +1 -1
  70. package/dist-server/service/connection/connection-type.d.ts +10 -99
  71. package/dist-server/service/connection/connection-type.js +36 -182
  72. package/dist-server/service/connection/connection-type.js.map +1 -1
  73. package/dist-server/service/connection/connection.d.ts +119 -0
  74. package/dist-server/service/connection/connection.js +239 -0
  75. package/dist-server/service/connection/connection.js.map +1 -0
  76. package/dist-server/service/connection/index.d.ts +1 -1
  77. package/dist-server/service/connection/index.js +2 -2
  78. package/dist-server/service/connection/index.js.map +1 -1
  79. package/dist-server/service/connector/connector-query.js +2 -2
  80. package/dist-server/service/connector/connector-query.js.map +1 -1
  81. package/dist-server/service/index.d.ts +1 -0
  82. package/dist-server/service/index.js +1 -0
  83. package/dist-server/service/index.js.map +1 -1
  84. package/dist-server/service/property-spec.d.ts +1 -0
  85. package/dist-server/service/property-spec.js +8 -1
  86. package/dist-server/service/property-spec.js.map +1 -1
  87. package/dist-server/service/scenario/scenario-mutation.js +1 -1
  88. package/dist-server/service/scenario/scenario-mutation.js.map +1 -1
  89. package/dist-server/service/scenario/scenario-query.js +3 -3
  90. package/dist-server/service/scenario/scenario-query.js.map +1 -1
  91. package/dist-server/service/scenario/scenario-type.js +4 -1
  92. package/dist-server/service/scenario/scenario-type.js.map +1 -1
  93. package/dist-server/service/scenario/scenario.js +1 -1
  94. package/dist-server/service/scenario/scenario.js.map +1 -1
  95. package/dist-server/service/task-type/task-type-query.js +2 -2
  96. package/dist-server/service/task-type/task-type-query.js.map +1 -1
  97. package/dist-server/tsconfig.tsbuildinfo +1 -1
  98. package/package.json +8 -8
@@ -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(connection_type_1.Connection).save({
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(connection_type_1.Connection);
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(connection_type_1.Connection);
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(connection_type_1.Connection).delete({ domain: { id: domain.id }, name });
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(connection_type_1.Connection).delete({
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,39 +77,78 @@ 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)(connection_type_1.Connection);
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']
83
84
  });
84
- await connection.connect();
85
- await repository.save(connection);
85
+ if (!connection) {
86
+ if (domain.parentId) {
87
+ connection = await repository.findOne({
88
+ where: { domain: { id: domain.parentId }, name },
89
+ relations: ['domain', 'edge']
90
+ });
91
+ }
92
+ if (!connection) {
93
+ throw new Error(`Connection with name '${name}' not found`);
94
+ }
95
+ }
96
+ /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */
97
+ if (connection.domain.id !== domain.id) {
98
+ connection.domain = domain;
99
+ await connection.connect();
100
+ /* on-demand 연결인 경우에 connection을 저장하지 말아야 한다. */
101
+ }
102
+ else {
103
+ await connection.connect();
104
+ await repository.save(connection);
105
+ }
86
106
  return {
87
107
  ...connection,
88
108
  state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
89
- ? connection_type_1.ConnectionStatus.CONNECTED
90
- : connection_type_1.ConnectionStatus.DISCONNECTED
109
+ ? connection_1.ConnectionStatus.CONNECTED
110
+ : connection_1.ConnectionStatus.DISCONNECTED
91
111
  };
92
112
  }
93
113
  async disconnectConnection(name, context) {
94
114
  const { domain } = context.state;
95
- var repository = (0, shell_1.getRepository)(connection_type_1.Connection);
115
+ var repository = (0, shell_1.getRepository)(connection_1.Connection);
96
116
  var connection = await repository.findOne({
97
117
  where: { domain: { id: domain.id }, name },
98
118
  relations: ['domain', 'edge']
99
119
  });
100
- await connection.disconnect();
101
- await repository.save(connection);
120
+ if (!connection) {
121
+ if (domain.parentId) {
122
+ connection = await repository.findOne({
123
+ where: { domain: { id: domain.parentId }, name },
124
+ relations: ['domain', 'edge']
125
+ });
126
+ }
127
+ if (!connection) {
128
+ throw new Error(`Connection with name '${name}' not found`);
129
+ }
130
+ }
131
+ /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */
132
+ /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */
133
+ if (connection.domain.id !== domain.id) {
134
+ connection.domain = domain;
135
+ await connection.disconnect();
136
+ /* on-demand 연결인 경우에 connection을 저장하지 말아야 한다. */
137
+ }
138
+ else {
139
+ await connection.disconnect();
140
+ await repository.save(connection);
141
+ }
102
142
  return {
103
143
  ...connection,
104
144
  state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
105
- ? connection_type_1.ConnectionStatus.CONNECTED
106
- : connection_type_1.ConnectionStatus.DISCONNECTED
145
+ ? connection_1.ConnectionStatus.CONNECTED
146
+ : connection_1.ConnectionStatus.DISCONNECTED
107
147
  };
108
148
  }
109
149
  async importConnections(connections, context) {
110
150
  const { tx, domain, user } = context.state;
111
- const repository = tx.getRepository(connection_type_1.Connection);
151
+ const repository = tx.getRepository(connection_1.Connection);
112
152
  await Promise.all(connections.map(async (connection) => {
113
153
  const { id, name } = connection;
114
154
  if (id) {
@@ -144,7 +184,7 @@ exports.ConnectionMutation = ConnectionMutation;
144
184
  tslib_1.__decorate([
145
185
  (0, type_graphql_1.Directive)('@transaction'),
146
186
  (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
147
- (0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'Creates a new connection.' }),
187
+ (0, type_graphql_1.Mutation)(returns => connection_1.Connection, { description: 'Creates a new connection.' }),
148
188
  tslib_1.__param(0, (0, type_graphql_1.Arg)('connection')),
149
189
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
150
190
  tslib_1.__metadata("design:type", Function),
@@ -154,7 +194,7 @@ tslib_1.__decorate([
154
194
  tslib_1.__decorate([
155
195
  (0, type_graphql_1.Directive)('@transaction'),
156
196
  (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
157
- (0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'Updates an existing connection.' }),
197
+ (0, type_graphql_1.Mutation)(returns => connection_1.Connection, { description: 'Updates an existing connection.' }),
158
198
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
159
199
  tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
160
200
  tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
@@ -165,7 +205,7 @@ tslib_1.__decorate([
165
205
  tslib_1.__decorate([
166
206
  (0, type_graphql_1.Directive)('@transaction'),
167
207
  (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
168
- (0, type_graphql_1.Mutation)(returns => [connection_type_1.Connection], { description: 'Updates multiple connections at once.' }),
208
+ (0, type_graphql_1.Mutation)(returns => [connection_1.Connection], { description: 'Updates multiple connections at once.' }),
169
209
  tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [connection_type_1.ConnectionPatch])),
170
210
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
171
211
  tslib_1.__metadata("design:type", Function),
@@ -195,7 +235,7 @@ tslib_1.__decorate([
195
235
  tslib_1.__decorate([
196
236
  (0, type_graphql_1.Directive)('@transaction'),
197
237
  (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
198
- (0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'Establishes a live connection to a configured endpoint.' }),
238
+ (0, type_graphql_1.Mutation)(returns => connection_1.Connection, { description: 'Establishes a live connection to a configured endpoint.' }),
199
239
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
200
240
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
201
241
  tslib_1.__metadata("design:type", Function),
@@ -205,7 +245,7 @@ tslib_1.__decorate([
205
245
  tslib_1.__decorate([
206
246
  (0, type_graphql_1.Directive)('@transaction'),
207
247
  (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
208
- (0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'Terminates a live connection.' }),
248
+ (0, type_graphql_1.Mutation)(returns => connection_1.Connection, { description: 'Terminates a live connection.' }),
209
249
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
210
250
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
211
251
  tslib_1.__metadata("design:type", Function),
@@ -225,6 +265,6 @@ tslib_1.__decorate([
225
265
  tslib_1.__metadata("design:returntype", Promise)
226
266
  ], ConnectionMutation.prototype, "importConnections", null);
227
267
  exports.ConnectionMutation = ConnectionMutation = tslib_1.__decorate([
228
- (0, type_graphql_1.Resolver)(connection_type_1.Connection)
268
+ (0, type_graphql_1.Resolver)(connection_1.Connection)
229
269
  ], ConnectionMutation);
230
270
  //# 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,GA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AC,OAAO,CAAC,EAAE,CAAC,4BAAU,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;IACtD,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;8DAkB3D;AASK;IAPL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EACR,6GAA6G,CAC9G;IACA,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE;QAC5B,WAAW,EAAE,yFAAyF;KACvG,CAAC;IAEC,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,iCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DA4CP;6BAlOU,kBAAkB;IAD9B,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-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AAErD,wEAAmE;AACnE,6CAA2D;AAC3D,uDAAkE;AAG3D,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,uBAAU,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,uBAAU,CAA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uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,uBAAU,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;IACtD,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;8DAyC3D;AASK;IAPL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EACR,6GAA6G,CAC9G;IACA,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE;QAC5B,WAAW,EAAE,yFAAyF;KACvG,CAAC;IAEC,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,iCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DA4CP;6BA7QU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,uBAAU,CAAC;GACR,kBAAkB,CA8Q9B","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, 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 if (!connection) {\n if (domain.parentId) {\n connection = await repository.findOne({\n where: { domain: { id: domain.parentId }, name },\n relations: ['domain', 'edge']\n })\n }\n\n if (!connection) {\n throw new Error(`Connection with name '${name}' not found`)\n }\n }\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n if (connection.domain.id !== domain.id) {\n connection.domain = domain\n await connection.connect()\n /* on-demand 연결인 경우에 connection을 저장하지 말아야 한다. */\n } else {\n await connection.connect()\n await repository.save(connection)\n }\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 if (!connection) {\n if (domain.parentId) {\n connection = await repository.findOne({\n where: { domain: { id: domain.parentId }, name },\n relations: ['domain', 'edge']\n })\n }\n\n if (!connection) {\n throw new Error(`Connection with name '${name}' not found`)\n }\n }\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n if (connection.domain.id !== domain.id) {\n connection.domain = domain\n await connection.disconnect()\n\n /* on-demand 연결인 경우에 connection을 저장하지 말아야 한다. */\n } else {\n await connection.disconnect()\n await repository.save(connection)\n }\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, ConnectionList, ConnectionState } from './connection-type';
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
  */
@@ -6,6 +6,7 @@ const type_graphql_1 = require("type-graphql");
6
6
  const auth_base_1 = require("@things-factory/auth-base");
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
  /**
11
12
  * @description Provides GraphQL resolvers for the Connection entity.
@@ -13,21 +14,21 @@ const connection_type_1 = require("./connection-type");
13
14
  let ConnectionQuery = class ConnectionQuery {
14
15
  async connection(name, context) {
15
16
  const { domain } = context.state;
16
- var connection = await (0, shell_1.getRepository)(connection_type_1.Connection).findOne({
17
+ var connection = await (0, shell_1.getRepository)(connection_1.Connection).findOne({
17
18
  where: { domain: { id: domain.id }, name },
18
19
  relations: ['domain']
19
20
  });
20
21
  return {
21
22
  ...connection,
22
23
  state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
23
- ? connection_type_1.ConnectionStatus.CONNECTED
24
- : connection_type_1.ConnectionStatus.DISCONNECTED
24
+ ? connection_1.ConnectionStatus.CONNECTED
25
+ : connection_1.ConnectionStatus.DISCONNECTED
25
26
  };
26
27
  }
27
28
  async connections(params, context) {
28
29
  const { domain } = context.state;
29
30
  const queryBuilder = (0, shell_1.getQueryBuilderFromListParams)({
30
- repository: (0, shell_1.getRepository)(connection_type_1.Connection),
31
+ repository: (0, shell_1.getRepository)(connection_1.Connection),
31
32
  params,
32
33
  domain,
33
34
  alias: 'connection',
@@ -36,8 +37,8 @@ let ConnectionQuery = class ConnectionQuery {
36
37
  const [items, total] = await queryBuilder.leftJoinAndSelect('connection.domain', 'domain').getManyAndCount();
37
38
  items.forEach(connection => {
38
39
  connection['state'] = connection_manager_1.ConnectionManager.getConnectionInstance(connection)
39
- ? connection_type_1.ConnectionStatus.CONNECTED
40
- : connection_type_1.ConnectionStatus.DISCONNECTED;
40
+ ? connection_1.ConnectionStatus.CONNECTED
41
+ : connection_1.ConnectionStatus.DISCONNECTED;
41
42
  });
42
43
  return { items, total };
43
44
  }
@@ -46,7 +47,7 @@ let ConnectionQuery = class ConnectionQuery {
46
47
  const connection = connection_manager_1.ConnectionManager.getConnectionInstanceEntityByName(domain, name);
47
48
  return {
48
49
  ...connection,
49
- state: connection ? connection_type_1.ConnectionStatus.CONNECTED : connection_type_1.ConnectionStatus.DISCONNECTED
50
+ state: connection ? connection_1.ConnectionStatus.CONNECTED : connection_1.ConnectionStatus.DISCONNECTED
50
51
  };
51
52
  }
52
53
  async edge(connection) {
@@ -65,7 +66,7 @@ let ConnectionQuery = class ConnectionQuery {
65
66
  exports.ConnectionQuery = ConnectionQuery;
66
67
  tslib_1.__decorate([
67
68
  (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
68
- (0, type_graphql_1.Query)(returns => connection_type_1.Connection, {
69
+ (0, type_graphql_1.Query)(returns => connection_1.Connection, {
69
70
  description: 'Fetches a single connection by its name, including its current state.'
70
71
  }),
71
72
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
@@ -98,31 +99,31 @@ tslib_1.__decorate([
98
99
  (0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
99
100
  tslib_1.__param(0, (0, type_graphql_1.Root)()),
100
101
  tslib_1.__metadata("design:type", Function),
101
- tslib_1.__metadata("design:paramtypes", [connection_type_1.Connection]),
102
+ tslib_1.__metadata("design:paramtypes", [connection_1.Connection]),
102
103
  tslib_1.__metadata("design:returntype", Promise)
103
104
  ], ConnectionQuery.prototype, "edge", null);
104
105
  tslib_1.__decorate([
105
106
  (0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
106
107
  tslib_1.__param(0, (0, type_graphql_1.Root)()),
107
108
  tslib_1.__metadata("design:type", Function),
108
- tslib_1.__metadata("design:paramtypes", [connection_type_1.Connection]),
109
+ tslib_1.__metadata("design:paramtypes", [connection_1.Connection]),
109
110
  tslib_1.__metadata("design:returntype", Promise)
110
111
  ], ConnectionQuery.prototype, "domain", null);
111
112
  tslib_1.__decorate([
112
113
  (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
113
114
  tslib_1.__param(0, (0, type_graphql_1.Root)()),
114
115
  tslib_1.__metadata("design:type", Function),
115
- tslib_1.__metadata("design:paramtypes", [connection_type_1.Connection]),
116
+ tslib_1.__metadata("design:paramtypes", [connection_1.Connection]),
116
117
  tslib_1.__metadata("design:returntype", Promise)
117
118
  ], ConnectionQuery.prototype, "updater", null);
118
119
  tslib_1.__decorate([
119
120
  (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
120
121
  tslib_1.__param(0, (0, type_graphql_1.Root)()),
121
122
  tslib_1.__metadata("design:type", Function),
122
- tslib_1.__metadata("design:paramtypes", [connection_type_1.Connection]),
123
+ tslib_1.__metadata("design:paramtypes", [connection_1.Connection]),
123
124
  tslib_1.__metadata("design:returntype", Promise)
124
125
  ], ConnectionQuery.prototype, "creator", null);
125
126
  exports.ConnectionQuery = ConnectionQuery = tslib_1.__decorate([
126
- (0, type_graphql_1.Resolver)(connection_type_1.Connection)
127
+ (0, type_graphql_1.Resolver)(connection_1.Connection)
127
128
  ], ConnectionQuery);
128
129
  //# sourceMappingURL=connection-query.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection-query.js","sourceRoot":"","sources":["../../../server/service/connection/connection-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAE9F,yDAA2D;AAC3D,iDAAuG;AAEvG,wEAAmE;AACnE,uDAAiG;AAEjG;;GAEG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAKpB,AAAN,KAAK,CAAC,UAAU,CAAc,IAAY,EAAS,OAAwB;QACzE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,IAAI,UAAU,GAAG,MAAM,IAAA,qBAAa,EAAC,4BAAU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AI,GAAE,CAAA;;6CAAa,4BAAU;;8CAE3C;0BAnFU,eAAe;IAD3B,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,eAAe,CAoF3B","sourcesContent":["import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'\n\nimport { Appliance, User } from '@things-factory/auth-base'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionList, ConnectionState, ConnectionStatus } from './connection-type'\n\n/**\n * @description Provides GraphQL resolvers for the Connection entity.\n */\n@Resolver(Connection)\nexport class ConnectionQuery {\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => Connection, {\n description: 'Fetches a single connection by its name, including its current state.'\n })\n async connection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain } = context.state\n\n var connection = await getRepository(Connection).findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain']\n })\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => ConnectionList, {\n description: 'Fetches a paginated list of connections, including their current states.'\n })\n async connections(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<ConnectionList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n repository: getRepository(Connection),\n params,\n domain,\n alias: 'connection',\n searchables: ['name', 'description', 'type', 'endpoint']\n })\n\n const [items, total] = await queryBuilder.leftJoinAndSelect('connection.domain', 'domain').getManyAndCount()\n\n items.forEach(connection => {\n connection['state'] = ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n })\n\n return { items, total }\n }\n\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => ConnectionState, { description: 'Fetches the current state of a single connection by its name.' })\n fetchConnectionState(@Arg('name') name: string, @Ctx() context: ResolverContext): ConnectionState {\n const { domain } = context.state\n\n const connection = ConnectionManager.getConnectionInstanceEntityByName(domain, name)\n\n return {\n ...connection,\n state: connection ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED\n }\n }\n\n @FieldResolver(type => Domain)\n async edge(@Root() connection: Connection) {\n return connection.edgeId && (await getRepository(Appliance).findOneBy({ id: connection.edgeId }))\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() connection: Connection) {\n return (\n connection.domain || (connection.domainId && (await getRepository(Domain).findOneBy({ id: connection.domainId })))\n )\n }\n\n @FieldResolver(type => User)\n async updater(@Root() connection: Connection): Promise<User> {\n return connection.updaterId && (await getRepository(User).findOneBy({ id: connection.updaterId }))\n }\n\n @FieldResolver(type => User)\n async creator(@Root() connection: Connection): Promise<User> {\n return connection.creatorId && (await getRepository(User).findOneBy({ id: connection.creatorId }))\n }\n}\n"]}
1
+ {"version":3,"file":"connection-query.js","sourceRoot":"","sources":["../../../server/service/connection/connection-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAE9F,yDAA2D;AAC3D,iDAAuG;AAEvG,wEAAmE;AACnE,6CAA2D;AAC3D,uDAAmE;AAEnE;;GAEG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAKpB,AAAN,KAAK,CAAC,UAAU,CAAc,IAAY,EAAS,OAAwB;QACzE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,IAAI,UAAU,GAAG,MAAM,IAAA,qBAAa,EAAC,uBAAU,CAAC,CAAC,OAAO,CAAC;YACvD,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE;YA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["import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'\n\nimport { Appliance, User } from '@things-factory/auth-base'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionStatus } from './connection'\nimport { ConnectionList, ConnectionState } from './connection-type'\n\n/**\n * @description Provides GraphQL resolvers for the Connection entity.\n */\n@Resolver(Connection)\nexport class ConnectionQuery {\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => Connection, {\n description: 'Fetches a single connection by its name, including its current state.'\n })\n async connection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain } = context.state\n\n var connection = await getRepository(Connection).findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain']\n })\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => ConnectionList, {\n description: 'Fetches a paginated list of connections, including their current states.'\n })\n async connections(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<ConnectionList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n repository: getRepository(Connection),\n params,\n domain,\n alias: 'connection',\n searchables: ['name', 'description', 'type', 'endpoint']\n })\n\n const [items, total] = await queryBuilder.leftJoinAndSelect('connection.domain', 'domain').getManyAndCount()\n\n items.forEach(connection => {\n connection['state'] = ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n })\n\n return { items, total }\n }\n\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => ConnectionState, { description: 'Fetches the current state of a single connection by its name.' })\n fetchConnectionState(@Arg('name') name: string, @Ctx() context: ResolverContext): ConnectionState {\n const { domain } = context.state\n\n const connection = ConnectionManager.getConnectionInstanceEntityByName(domain, name)\n\n return {\n ...connection,\n state: connection ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED\n }\n }\n\n @FieldResolver(type => Domain)\n async edge(@Root() connection: Connection) {\n return connection.edgeId && (await getRepository(Appliance).findOneBy({ id: connection.edgeId }))\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() connection: Connection) {\n return (\n connection.domain || (connection.domainId && (await getRepository(Domain).findOneBy({ id: connection.domainId })))\n )\n }\n\n @FieldResolver(type => User)\n async updater(@Root() connection: Connection): Promise<User> {\n return connection.updaterId && (await getRepository(User).findOneBy({ id: connection.updaterId }))\n }\n\n @FieldResolver(type => User)\n async creator(@Root() connection: Connection): Promise<User> {\n return connection.creatorId && (await getRepository(User).findOneBy({ id: connection.creatorId }))\n }\n}\n"]}
@@ -6,6 +6,7 @@ const graphql_yoga_1 = require("graphql-yoga");
6
6
  const type_graphql_1 = require("type-graphql");
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
  const debug = require('debug')('things-factory:integration:connection-subscription');
11
12
  let ConnectionSubscription = class ConnectionSubscription {
@@ -36,7 +37,7 @@ tslib_1.__decorate([
36
37
  if (name) {
37
38
  where['name'] = name;
38
39
  }
39
- var connections = await (0, shell_1.getRepository)(connection_type_1.Connection).find({
40
+ var connections = await (0, shell_1.getRepository)(connection_1.Connection).find({
40
41
  where,
41
42
  relations: ['domain', 'edge']
42
43
  });
@@ -44,9 +45,10 @@ tslib_1.__decorate([
44
45
  shell_1.pubsub.publish('connection-state', {
45
46
  connectionState: {
46
47
  ...connection,
48
+ domain /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */,
47
49
  state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
48
- ? connection_type_1.ConnectionStatus.CONNECTED
49
- : connection_type_1.ConnectionStatus.DISCONNECTED,
50
+ ? connection_1.ConnectionStatus.CONNECTED
51
+ : connection_1.ConnectionStatus.DISCONNECTED,
50
52
  timestamp: new Date()
51
53
  }
52
54
  });
@@ -99,6 +101,6 @@ tslib_1.__decorate([
99
101
  tslib_1.__metadata("design:returntype", shell_1.Log)
100
102
  ], ConnectionSubscription.prototype, "connectionLog", null);
101
103
  exports.ConnectionSubscription = ConnectionSubscription = tslib_1.__decorate([
102
- (0, type_graphql_1.Resolver)(connection_type_1.Connection)
104
+ (0, type_graphql_1.Resolver)(connection_1.Connection)
103
105
  ], ConnectionSubscription);
104
106
  //# sourceMappingURL=connection-subscription.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection-subscription.js","sourceRoot":"","sources":["../../../server/service/connection/connection-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAAgE;AAEhE,iDAAkE;AAElE,wEAAmE;AACnE,uDAAiF;AAEjF,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAG7E,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAmDjC,eAAe,CACL,OAA6C,EACpB,IAAY;QAE7C,OAAO,OAAO,CAAC,eAAe,CAAA;IAChC,CAAC;IAwCD,aAAa,CAAS,OAAqB,EAAoC,KAAa;QAC1F,OAAO,OAAO,CAAC,GAAG,CAAA;IACpB,CAAC;CACF,CAAA;AAnGY,wDAAsB;AAmDjC;IAlDC,IAAA,2BAAY,EAAC;QACZ,WAAW,EAAE,iDAAiD;QAC9D,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;YACrC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;YACtC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;YACr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AI,KAAK,CAAC,UAAU,SAAS,6BAA6B,IAAI,CAAC,KAAK,IAAI,CAAC,CAAA;YACjF,CAAC;YAED,OAAO,IAAA,mBAAI,EACT,cAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAClC,IAAA,qBAAM,EAAC,KAAK,EAAE,OAAqB,EAAE,EAAE;gBACrC,gCAAgC;gBAChC,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;gBACnD,qCAAqC;gBAErC,0CAA0C;gBAC1C,iBAAiB;gBACjB,IAAI;gBAEJ,IAAI,KAAK,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;oBAC9B,OAAO,KAAK,CAAA;gBACd,CAAC;gBAED,OAAO,IAAI,CAAA;YACb,CAAC,CAAC,CACH,CAAA;QACH,CAAC;KACF,CAAC;IACa,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAAyB,mBAAA,IAAA,kBAAG,EAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;;;4CAAiB,WAAG;2DAEjG;iCAlGU,sBAAsB;IADlC,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,sBAAsB,CAmGlC","sourcesContent":["import { filter, pipe } from 'graphql-yoga'\nimport { Arg, Resolver, Root, Subscription } from 'type-graphql'\n\nimport { getRepository, Log, pubsub } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionState, ConnectionStatus } from './connection-type'\n\nconst debug = require('debug')('things-factory:integration:connection-subscription')\n\n@Resolver(Connection)\nexport class ConnectionSubscription {\n @Subscription({\n description: 'Subscribes to the state changes of connections.',\n subscribe: ({ args, context, info }) => {\n const { domain, user } = context.state\n const { name } = args\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain)\n if (!domain) {\n throw new Error('domain required.')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n process.nextTick(async () => {\n var where = { domain: { id: domain.id } }\n if (name) {\n where['name'] = name\n }\n\n var connections = await getRepository(Connection).find({\n where,\n relations: ['domain', 'edge']\n })\n\n connections.forEach(connection => {\n pubsub.publish('connection-state', {\n connectionState: {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED,\n timestamp: new Date()\n }\n })\n })\n })\n\n return pipe(\n pubsub.subscribe('connection-state'),\n filter(async (payload: { connectionState: ConnectionState }) => {\n const { domain: pdomain, name: pname } = payload.connectionState\n\n return (!name || name === pname) && subdomain === pdomain?.subdomain\n })\n )\n }\n })\n connectionState(\n @Root() payload: { connectionState: ConnectionState },\n @Arg('name', { nullable: true }) name: string\n ): ConnectionState {\n return payload.connectionState\n }\n\n @Subscription({\n description: 'Subscribes to log messages from connections.',\n subscribe: ({ args, context, info }) => {\n const { domain, user } = context.state\n const { level } = args\n\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain)\n\n if (!domain) {\n throw new Error('domain required')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n return pipe(\n pubsub.subscribe('connection-log'),\n filter(async (payload: { log: Log }) => {\n // TODO support domain filtering\n const { /* source, */ level: plevel } = payload.log\n // const { domain: pdomain } = source\n\n // if (subdomain !== pdomain?.subdomain) {\n // return false\n // }\n\n if (level && level !== plevel) {\n return false\n }\n\n return true\n })\n )\n }\n })\n connectionLog(@Root() payload: { log: Log }, @Arg('level', { nullable: true }) level: string): Log {\n return payload.log\n }\n}\n"]}
1
+ {"version":3,"file":"connection-subscription.js","sourceRoot":"","sources":["../../../server/service/connection/connection-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAAgE;AAEhE,iDAAkE;AAElE,wEAAmE;AACn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IAAA,kBAAG,EAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;;;4CAAiB,WAAG;2DAEjG;iCAnGU,sBAAsB;IADlC,IAAA,uBAAQ,EAAC,uBAAU,CAAC;GACR,sBAAsB,CAoGlC","sourcesContent":["import { filter, pipe } from 'graphql-yoga'\nimport { Arg, Resolver, Root, Subscription } from 'type-graphql'\n\nimport { getRepository, Log, pubsub } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionStatus } from './connection'\nimport { ConnectionState } from './connection-type'\n\nconst debug = require('debug')('things-factory:integration:connection-subscription')\n\n@Resolver(Connection)\nexport class ConnectionSubscription {\n @Subscription({\n description: 'Subscribes to the state changes of connections.',\n subscribe: ({ args, context, info }) => {\n const { domain, user } = context.state\n const { name } = args\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain)\n if (!domain) {\n throw new Error('domain required.')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n process.nextTick(async () => {\n var where = { domain: { id: domain.id } }\n if (name) {\n where['name'] = name\n }\n\n var connections = await getRepository(Connection).find({\n where,\n relations: ['domain', 'edge']\n })\n\n connections.forEach(connection => {\n pubsub.publish('connection-state', {\n connectionState: {\n ...connection,\n domain /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED,\n timestamp: new Date()\n }\n })\n })\n })\n\n return pipe(\n pubsub.subscribe('connection-state'),\n filter(async (payload: { connectionState: ConnectionState }) => {\n const { domain: pdomain, name: pname } = payload.connectionState\n\n return (!name || name === pname) && subdomain === pdomain?.subdomain\n })\n )\n }\n })\n connectionState(\n @Root() payload: { connectionState: ConnectionState },\n @Arg('name', { nullable: true }) name: string\n ): ConnectionState {\n return payload.connectionState\n }\n\n @Subscription({\n description: 'Subscribes to log messages from connections.',\n subscribe: ({ args, context, info }) => {\n const { domain, user } = context.state\n const { level } = args\n\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain)\n\n if (!domain) {\n throw new Error('domain required')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n return pipe(\n pubsub.subscribe('connection-log'),\n filter(async (payload: { log: Log }) => {\n // TODO support domain filtering\n const { /* source, */ level: plevel } = payload.log\n // const { domain: pdomain } = source\n\n // if (subdomain !== pdomain?.subdomain) {\n // return false\n // }\n\n if (level && level !== plevel) {\n return false\n }\n\n return true\n })\n )\n }\n })\n connectionLog(@Root() payload: { log: Log }, @Arg('level', { nullable: true }) level: string): Log {\n return payload.log\n }\n}\n"]}
@@ -1,109 +1,16 @@
1
- import { User, Appliance } from '@things-factory/auth-base';
1
+ import { Appliance } from '@things-factory/auth-base';
2
2
  import { Domain } from '@things-factory/shell';
3
- export declare enum ConnectionStatus {
4
- CONNECTED = "CONNECTED",// Represents an active, established connection.
5
- DISCONNECTED = "DISCONNECTED"
6
- }
7
- export declare class Connection {
8
- /**
9
- * Unique identifier for the connection, generated in UUID format.
10
- */
11
- readonly id: string;
12
- /**
13
- * Many-to-One relationship with the Domain entity.
14
- */
15
- domain: Domain;
16
- /**
17
- * Stores the ID of the associated Domain.
18
- */
19
- domainId: string;
20
- /**
21
- * The name of the connection.
22
- */
23
- name: string;
24
- /**
25
- * Optional description for the connection.
26
- */
27
- description: string;
28
- /**
29
- * The type of the connection.
30
- */
31
- type: string;
32
- /**
33
- * Many-to-One relationship with the Appliance entity which delegate the connection. Optional field.
34
- */
35
- edge: Appliance;
36
- /**
37
- * Stores the ID of the Appliance who delegate the connection.
38
- */
39
- edgeId: string;
40
- /**
41
- * The endpoint for the connection.
42
- */
43
- endpoint: string;
44
- /**
45
- * Indicates the active status of the connection.
46
- */
47
- active: boolean;
48
- /**
49
- * The status of the connection, using the ConnectionStatus type.
50
- */
51
- state: ConnectionStatus;
52
- /**
53
- * Additional parameters for the connection, stored as a JSON string.
54
- *
55
- * [Caution]
56
- * 이 컬럼타입은 postgres 데이터베이스에서는 varchar 타입을 유지한다.
57
- * 이는 데이터베이스 타입을 변경하면 기존 데이터가 손실될 수 있기 때문이다.
58
- * 'simple-json' 타입으로 변경 전에 postgres 데이타베이스에 이미 varchar 타입으로 사용한 사례가 많기 때문이다.
59
- */
60
- params: {
61
- [key: string]: any;
62
- };
63
- /**
64
- * The date and time when the connection was created.
65
- */
66
- createdAt: Date;
67
- /**
68
- * The date and time when the connection was last updated.
69
- */
70
- updatedAt: Date;
71
- /**
72
- * Many-to-One relationship with the User entity who created the connection. Optional field.
73
- */
74
- creator: User;
75
- /**
76
- * Stores the ID of the User who created the connection.
77
- */
78
- creatorId: string;
79
- /**
80
- * Many-to-One relationship with the User entity who last updated the connection.
81
- * Optional field.
82
- */
83
- updater: User;
84
- /**
85
- * Stores the ID of the User who last updated the connection.
86
- *
87
- */
88
- updaterId: string;
89
- /**
90
- * Asynchronous method to establish the connection.
91
- *
92
- */
93
- connect(): Promise<void>;
94
- /**
95
- * @brief Asynchronous method to disconnect the connection.
96
- *
97
- */
98
- disconnect(): Promise<void>;
99
- }
3
+ import { Connection } from './connection';
4
+ import { ConnectionStatus } from './connection';
100
5
  /**
101
6
  * Connection의 params의 원 타입과 사용 시에 타입 불일치로 인해 임시적으로 생성한 타입으로
102
7
  * 추후, 타입 일치를 통해서 제거할 예정임.
103
8
  *
104
9
  */
105
10
  export interface InputConnection extends Connection {
106
- params: any;
11
+ params: {
12
+ [key: string]: any;
13
+ };
107
14
  }
108
15
  export declare class ConnectionState {
109
16
  domain?: Domain;
@@ -111,6 +18,7 @@ export declare class ConnectionState {
111
18
  name?: string;
112
19
  description?: string;
113
20
  type?: string;
21
+ onDemand?: boolean;
114
22
  edge?: Appliance;
115
23
  state?: ConnectionStatus;
116
24
  timestamp?: Date;
@@ -119,8 +27,10 @@ export declare class NewConnection {
119
27
  name: string;
120
28
  description?: string;
121
29
  type?: string;
30
+ onDemand: boolean;
122
31
  edge?: Appliance;
123
32
  endpoint?: string;
33
+ active?: boolean;
124
34
  params?: {
125
35
  [key: string]: any;
126
36
  };
@@ -130,6 +40,7 @@ export declare class ConnectionPatch {
130
40
  name?: string;
131
41
  description?: string;
132
42
  type?: string;
43
+ onDemand: boolean;
133
44
  edge?: Appliance;
134
45
  endpoint?: string;
135
46
  active?: boolean;