@things-factory/integration-base 9.0.0-beta.8 → 9.0.0-beta.80
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/controllers/publish-data.js +7 -2
- package/dist-server/controllers/publish-data.js.map +1 -1
- package/dist-server/engine/analyzer/analyze-integration.js +1 -1
- package/dist-server/engine/analyzer/analyze-integration.js.map +1 -1
- package/dist-server/engine/connection-manager.js +41 -40
- package/dist-server/engine/connection-manager.js.map +1 -1
- package/dist-server/engine/connector/graphql-connector.js +4 -1
- package/dist-server/engine/connector/graphql-connector.js.map +1 -1
- package/dist-server/engine/connector/headless-connector.js +1 -2
- package/dist-server/engine/connector/headless-connector.js.map +1 -1
- package/dist-server/engine/connector/http-connector.js +5 -1
- package/dist-server/engine/connector/http-connector.js.map +1 -1
- package/dist-server/engine/connector/operato-connector.js +10 -8
- package/dist-server/engine/connector/operato-connector.js.map +1 -1
- package/dist-server/engine/connector/oracle-connector.js +2 -2
- package/dist-server/engine/connector/oracle-connector.js.map +1 -1
- package/dist-server/engine/connector/postgresql-connector.js +3 -3
- package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
- package/dist-server/engine/connector/proxy-connector.js +1 -1
- package/dist-server/engine/connector/proxy-connector.js.map +1 -1
- package/dist-server/engine/index.d.ts +2 -2
- package/dist-server/engine/index.js +2 -2
- package/dist-server/engine/index.js.map +1 -1
- package/dist-server/engine/scenario-engine.js +10 -7
- package/dist-server/engine/scenario-engine.js.map +1 -1
- package/dist-server/engine/task/headless-post.js +3 -1
- package/dist-server/engine/task/headless-post.js.map +1 -1
- package/dist-server/engine/task/headless-scrap.js +36 -4
- package/dist-server/engine/task/headless-scrap.js.map +1 -1
- package/dist-server/engine/task/http-get.js +4 -1
- package/dist-server/engine/task/http-get.js.map +1 -1
- package/dist-server/engine/task/http-post.js +4 -1
- package/dist-server/engine/task/http-post.js.map +1 -1
- package/dist-server/engine/task/mqtt-publish.js +29 -6
- package/dist-server/engine/task/mqtt-publish.js.map +1 -1
- package/dist-server/engine/task/mqtt-subscribe.d.ts +84 -0
- package/dist-server/engine/task/mqtt-subscribe.js +197 -79
- package/dist-server/engine/task/mqtt-subscribe.js.map +1 -1
- package/dist-server/engine/task/mssql-procedure.js +1 -1
- package/dist-server/engine/task/mssql-procedure.js.map +1 -1
- package/dist-server/engine/task/oracle-procedure.js +10 -10
- package/dist-server/engine/task/oracle-procedure.js.map +1 -1
- package/dist-server/engine/task/pick-pending-scenario.js +5 -1
- package/dist-server/engine/task/pick-pending-scenario.js.map +1 -1
- package/dist-server/engine/task/state-group-read.js +1 -2
- package/dist-server/engine/task/state-group-read.js.map +1 -1
- package/dist-server/engine/task/state-read.js +1 -2
- package/dist-server/engine/task/state-read.js.map +1 -1
- package/dist-server/engine/task/state-write.js +1 -2
- package/dist-server/engine/task/state-write.js.map +1 -1
- package/dist-server/engine/task/stop-scenario.js +3 -3
- package/dist-server/engine/task/stop-scenario.js.map +1 -1
- package/dist-server/engine/task/sub-scenario.js +5 -2
- package/dist-server/engine/task/sub-scenario.js.map +1 -1
- package/dist-server/engine/task/switch-range-scenario.js +5 -2
- package/dist-server/engine/task/switch-range-scenario.js.map +1 -1
- package/dist-server/engine/task/switch-scenario.js +5 -2
- package/dist-server/engine/task/switch-scenario.js.map +1 -1
- package/dist-server/engine/task/variables.js +1 -1
- package/dist-server/engine/task/variables.js.map +1 -1
- package/dist-server/engine/task-registry.js +4 -2
- package/dist-server/engine/task-registry.js.map +1 -1
- package/dist-server/index.d.ts +6 -6
- package/dist-server/index.js +10 -10
- package/dist-server/index.js.map +1 -1
- package/dist-server/routers/scenario-schedule-callback-router.js +2 -2
- package/dist-server/routers/scenario-schedule-callback-router.js.map +1 -1
- package/dist-server/routes.js +8 -7
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/connection/connection-mutation.d.ts +3 -1
- package/dist-server/service/connection/connection-mutation.js +59 -13
- package/dist-server/service/connection/connection-mutation.js.map +1 -1
- package/dist-server/service/connection/connection-query.js +12 -3
- package/dist-server/service/connection/connection-query.js.map +1 -1
- package/dist-server/service/connection/connection-subscription.js +10 -8
- package/dist-server/service/connection/connection-subscription.js.map +1 -1
- package/dist-server/service/connection/connection-type.d.ts +14 -3
- package/dist-server/service/connection/connection-type.js +29 -15
- package/dist-server/service/connection/connection-type.js.map +1 -1
- package/dist-server/service/payload-log/payload-log-mutation.js +25 -7
- package/dist-server/service/payload-log/payload-log-mutation.js.map +1 -1
- package/dist-server/service/scenario/scenario-mutation.js +56 -12
- package/dist-server/service/scenario/scenario-mutation.js.map +1 -1
- package/dist-server/service/scenario/scenario-query.js +2 -3
- package/dist-server/service/scenario/scenario-query.js.map +1 -1
- package/dist-server/service/scenario/scenario.js +5 -5
- package/dist-server/service/scenario/scenario.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-subscription.js +6 -8
- package/dist-server/service/scenario-instance/scenario-instance-subscription.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-type.js +26 -30
- package/dist-server/service/scenario-instance/scenario-instance-type.js.map +1 -1
- package/dist-server/service/scenario-queue/scenario-queue-subscription.js +3 -4
- package/dist-server/service/scenario-queue/scenario-queue-subscription.js.map +1 -1
- package/dist-server/service/state-register/data-resolver.js +3 -4
- package/dist-server/service/state-register/data-resolver.js.map +1 -1
- package/dist-server/service/state-register/state-register-mutation.js +32 -9
- package/dist-server/service/state-register/state-register-mutation.js.map +1 -1
- package/dist-server/service/state-register/state-register-query.js +1 -1
- package/dist-server/service/state-register/state-register-query.js.map +1 -1
- package/dist-server/service/step/step-mutation.js +9 -3
- package/dist-server/service/step/step-mutation.js.map +1 -1
- package/dist-server/service/step/step-type.d.ts +11 -3
- package/dist-server/service/step/step-type.js +24 -5
- package/dist-server/service/step/step-type.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/helps/integration/task/headless-scrap.ja.md +11 -4
- package/helps/integration/task/headless-scrap.ko.md +12 -5
- package/helps/integration/task/headless-scrap.md +10 -3
- package/helps/integration/task/headless-scrap.ms.md +9 -2
- package/helps/integration/task/headless-scrap.zh.md +9 -2
- package/package.json +11 -11
- package/translations/en.json +6 -1
- package/translations/ja.json +6 -1
- package/translations/ko.json +6 -1
- package/translations/ms.json +6 -1
- package/translations/zh.json +6 -1
@@ -10,7 +10,12 @@ const connection_type_1 = require("./connection-type");
|
|
10
10
|
let ConnectionMutation = class ConnectionMutation {
|
11
11
|
async createConnection(connection, context) {
|
12
12
|
const { domain, user, tx } = context.state;
|
13
|
-
return await tx.getRepository(connection_type_1.Connection).save(
|
13
|
+
return await tx.getRepository(connection_type_1.Connection).save({
|
14
|
+
...connection,
|
15
|
+
domain,
|
16
|
+
creator: user,
|
17
|
+
updater: user
|
18
|
+
});
|
14
19
|
}
|
15
20
|
async updateConnection(name, patch, context) {
|
16
21
|
const { domain, user, tx } = context.state;
|
@@ -18,7 +23,11 @@ let ConnectionMutation = class ConnectionMutation {
|
|
18
23
|
const connection = await repository.findOne({
|
19
24
|
where: { domain: { id: domain.id }, name }
|
20
25
|
});
|
21
|
-
return await repository.save(
|
26
|
+
return await repository.save({
|
27
|
+
...connection,
|
28
|
+
...patch,
|
29
|
+
updater: user
|
30
|
+
});
|
22
31
|
}
|
23
32
|
async updateMultipleConnection(patches, context) {
|
24
33
|
const { domain, user, tx } = context.state;
|
@@ -29,16 +38,25 @@ let ConnectionMutation = class ConnectionMutation {
|
|
29
38
|
if (_createRecords.length > 0) {
|
30
39
|
for (let i = 0; i < _createRecords.length; i++) {
|
31
40
|
const newRecord = _createRecords[i];
|
32
|
-
const result = await connectionRepo.save(
|
33
|
-
|
41
|
+
const result = await connectionRepo.save({
|
42
|
+
...newRecord,
|
43
|
+
domain,
|
44
|
+
creator: user,
|
45
|
+
updater: user
|
46
|
+
});
|
47
|
+
results.push({ ...result, cuFlag: '+' });
|
34
48
|
}
|
35
49
|
}
|
36
50
|
if (_updateRecords.length > 0) {
|
37
51
|
for (let i = 0; i < _updateRecords.length; i++) {
|
38
52
|
const newRecord = _updateRecords[i];
|
39
53
|
const connection = await connectionRepo.findOneBy({ id: newRecord.id });
|
40
|
-
const result = await connectionRepo.save(
|
41
|
-
|
54
|
+
const result = await connectionRepo.save({
|
55
|
+
...connection,
|
56
|
+
...newRecord,
|
57
|
+
updater: user
|
58
|
+
});
|
59
|
+
results.push({ ...result, cuFlag: 'M' });
|
42
60
|
}
|
43
61
|
}
|
44
62
|
return results;
|
@@ -65,7 +83,12 @@ let ConnectionMutation = class ConnectionMutation {
|
|
65
83
|
});
|
66
84
|
await connection.connect();
|
67
85
|
await repository.save(connection);
|
68
|
-
return
|
86
|
+
return {
|
87
|
+
...connection,
|
88
|
+
state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
|
89
|
+
? connection_type_1.ConnectionStatus.CONNECTED
|
90
|
+
: connection_type_1.ConnectionStatus.DISCONNECTED
|
91
|
+
};
|
69
92
|
}
|
70
93
|
async disconnectConnection(name, context) {
|
71
94
|
const { domain } = context.state;
|
@@ -76,7 +99,12 @@ let ConnectionMutation = class ConnectionMutation {
|
|
76
99
|
});
|
77
100
|
await connection.disconnect();
|
78
101
|
await repository.save(connection);
|
79
|
-
return
|
102
|
+
return {
|
103
|
+
...connection,
|
104
|
+
state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
|
105
|
+
? connection_type_1.ConnectionStatus.CONNECTED
|
106
|
+
: connection_type_1.ConnectionStatus.DISCONNECTED
|
107
|
+
};
|
80
108
|
}
|
81
109
|
async importConnections(connections, context) {
|
82
110
|
const { tx, domain, user } = context.state;
|
@@ -93,11 +121,21 @@ let ConnectionMutation = class ConnectionMutation {
|
|
93
121
|
if (sameName && sameName.id != id) {
|
94
122
|
throw `Connection with name '${name}' is already taken by another connection`;
|
95
123
|
}
|
96
|
-
await repository.save(
|
124
|
+
await repository.save({
|
125
|
+
...sameId,
|
126
|
+
...connection,
|
127
|
+
domain,
|
128
|
+
updater: user
|
129
|
+
});
|
97
130
|
return;
|
98
131
|
}
|
99
132
|
}
|
100
|
-
await repository.save(
|
133
|
+
await repository.save({
|
134
|
+
...connection,
|
135
|
+
domain,
|
136
|
+
updater: user,
|
137
|
+
creator: user
|
138
|
+
});
|
101
139
|
}));
|
102
140
|
return true;
|
103
141
|
}
|
@@ -105,6 +143,7 @@ let ConnectionMutation = class ConnectionMutation {
|
|
105
143
|
exports.ConnectionMutation = ConnectionMutation;
|
106
144
|
tslib_1.__decorate([
|
107
145
|
(0, type_graphql_1.Directive)('@transaction'),
|
146
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
108
147
|
(0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'To create new connection' }),
|
109
148
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('connection')),
|
110
149
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -114,6 +153,7 @@ tslib_1.__decorate([
|
|
114
153
|
], ConnectionMutation.prototype, "createConnection", null);
|
115
154
|
tslib_1.__decorate([
|
116
155
|
(0, type_graphql_1.Directive)('@transaction'),
|
156
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
117
157
|
(0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'To modify connection information' }),
|
118
158
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
119
159
|
tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
|
@@ -124,6 +164,7 @@ tslib_1.__decorate([
|
|
124
164
|
], ConnectionMutation.prototype, "updateConnection", null);
|
125
165
|
tslib_1.__decorate([
|
126
166
|
(0, type_graphql_1.Directive)('@transaction'),
|
167
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
127
168
|
(0, type_graphql_1.Mutation)(returns => [connection_type_1.Connection], { description: "To modify multiple connections' information" }),
|
128
169
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [connection_type_1.ConnectionPatch])),
|
129
170
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -133,6 +174,7 @@ tslib_1.__decorate([
|
|
133
174
|
], ConnectionMutation.prototype, "updateMultipleConnection", null);
|
134
175
|
tslib_1.__decorate([
|
135
176
|
(0, type_graphql_1.Directive)('@transaction'),
|
177
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
136
178
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete connection' }),
|
137
179
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
138
180
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -142,6 +184,7 @@ tslib_1.__decorate([
|
|
142
184
|
], ConnectionMutation.prototype, "deleteConnection", null);
|
143
185
|
tslib_1.__decorate([
|
144
186
|
(0, type_graphql_1.Directive)('@transaction'),
|
187
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
145
188
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete multiple connections' }),
|
146
189
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('names', type => [String])),
|
147
190
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -150,6 +193,8 @@ tslib_1.__decorate([
|
|
150
193
|
tslib_1.__metadata("design:returntype", Promise)
|
151
194
|
], ConnectionMutation.prototype, "deleteConnections", null);
|
152
195
|
tslib_1.__decorate([
|
196
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
197
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
153
198
|
(0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'To connect a connection' }),
|
154
199
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
155
200
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -158,6 +203,8 @@ tslib_1.__decorate([
|
|
158
203
|
tslib_1.__metadata("design:returntype", Promise)
|
159
204
|
], ConnectionMutation.prototype, "connectConnection", null);
|
160
205
|
tslib_1.__decorate([
|
206
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
207
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
161
208
|
(0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'To disconnect a connection' }),
|
162
209
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
163
210
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -166,9 +213,8 @@ tslib_1.__decorate([
|
|
166
213
|
tslib_1.__metadata("design:returntype", Promise)
|
167
214
|
], ConnectionMutation.prototype, "disconnectConnection", null);
|
168
215
|
tslib_1.__decorate([
|
169
|
-
(0, type_graphql_1.Directive)('@transaction')
|
170
|
-
|
171
|
-
,
|
216
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
217
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
172
218
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To import multiple connections' }),
|
173
219
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('connections', type => [connection_type_1.ConnectionPatch])),
|
174
220
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -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;IAGvB,AAAN,KAAK,CAAC,gBAAgB,CAAoB,UAAyB,EAAS,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mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;8DAgB3D;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IAC1B,oGAAoG;;IACnG,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IACvD,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,iCAAe,CAAC,CAAC,CAAA;IAA6B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DA2CvG;6BAnLU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,kBAAkB,CAoL9B","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 @Mutation(returns => Connection, { description: 'To create new connection' })\n async createConnection(@Arg('connection') connection: NewConnection, @Ctx() context: ResolverContext): 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 @Mutation(returns => Connection, { description: 'To modify connection information' })\n async updateConnection(@Arg('name') name: string, @Arg('patch') patch: ConnectionPatch, @Ctx() context: ResolverContext): 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 @Mutation(returns => [Connection], { description: \"To modify multiple connections' information\" })\n async updateMultipleConnection(@Arg('patches', type => [ConnectionPatch]) patches: ConnectionPatch[], @Ctx() context: ResolverContext): 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 @Mutation(returns => Boolean, { description: 'To delete connection' })\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 @Mutation(returns => Boolean, { description: 'To delete multiple connections' })\n async deleteConnections(@Arg('names', type => [String]) names: string[], @Ctx() context: ResolverContext): 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 @Mutation(returns => Connection, { description: 'To connect a connection' })\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) ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Mutation(returns => Connection, { description: 'To disconnect a 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) ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED\n }\n }\n\n @Directive('@transaction')\n // @Directive('@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To import multiple connections' })\n async importConnections(@Arg('connections', type => [ConnectionPatch]) connections: Connection[], @Ctx() context: ResolverContext): 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,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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CAC9G;IACA,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,4BAAU,EAAE,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;IACnD,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAiBxD;AAOK;IALL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EACR,6GAA6G,CAC9G;IACA,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,4BAAU,EAAE,EAAE,WAAW,EAAE,4BAA4B,EAAE,CAAC;IACnD,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;8DAkB3D;AAOK;IALL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EACR,6GAA6G,CAC9G;IACA,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IAE7E,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,iCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DA4CP;6BAhOU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,kBAAkB,CAiO9B","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: 'To create 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: 'To modify connection information' })\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: \"To modify multiple connections' information\" })\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: 'To delete connection' })\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: 'To delete multiple connections' })\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: 'To connect a connection' })\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: 'To disconnect a 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, { description: 'To import multiple connections' })\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"]}
|
@@ -14,9 +14,12 @@ let ConnectionQuery = class ConnectionQuery {
|
|
14
14
|
where: { domain: { id: domain.id }, name },
|
15
15
|
relations: ['domain']
|
16
16
|
});
|
17
|
-
return
|
17
|
+
return {
|
18
|
+
...connection,
|
19
|
+
state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
|
18
20
|
? connection_type_1.ConnectionStatus.CONNECTED
|
19
|
-
: connection_type_1.ConnectionStatus.DISCONNECTED
|
21
|
+
: connection_type_1.ConnectionStatus.DISCONNECTED
|
22
|
+
};
|
20
23
|
}
|
21
24
|
async connections(params, context) {
|
22
25
|
const { domain } = context.state;
|
@@ -38,7 +41,10 @@ let ConnectionQuery = class ConnectionQuery {
|
|
38
41
|
fetchConnectionState(name, context) {
|
39
42
|
const { domain } = context.state;
|
40
43
|
const connection = connection_manager_1.ConnectionManager.getConnectionInstanceEntityByName(domain, name);
|
41
|
-
return
|
44
|
+
return {
|
45
|
+
...connection,
|
46
|
+
state: connection ? connection_type_1.ConnectionStatus.CONNECTED : connection_type_1.ConnectionStatus.DISCONNECTED
|
47
|
+
};
|
42
48
|
}
|
43
49
|
async edge(connection) {
|
44
50
|
return connection.edgeId && (await (0, shell_1.getRepository)(auth_base_1.Appliance).findOneBy({ id: connection.edgeId }));
|
@@ -55,6 +61,7 @@ let ConnectionQuery = class ConnectionQuery {
|
|
55
61
|
};
|
56
62
|
exports.ConnectionQuery = ConnectionQuery;
|
57
63
|
tslib_1.__decorate([
|
64
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
|
58
65
|
(0, type_graphql_1.Query)(returns => connection_type_1.Connection, { description: 'To fetch a connection' }),
|
59
66
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
60
67
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -63,6 +70,7 @@ tslib_1.__decorate([
|
|
63
70
|
tslib_1.__metadata("design:returntype", Promise)
|
64
71
|
], ConnectionQuery.prototype, "connection", null);
|
65
72
|
tslib_1.__decorate([
|
73
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
|
66
74
|
(0, type_graphql_1.Query)(returns => connection_type_1.ConnectionList, { description: 'To fetch multiple connections' }),
|
67
75
|
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
68
76
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -71,6 +79,7 @@ tslib_1.__decorate([
|
|
71
79
|
tslib_1.__metadata("design:returntype", Promise)
|
72
80
|
], ConnectionQuery.prototype, "connections", null);
|
73
81
|
tslib_1.__decorate([
|
82
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
|
74
83
|
(0, type_graphql_1.Query)(returns => connection_type_1.ConnectionState, { description: 'To fetch the state of a connection' }),
|
75
84
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
76
85
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"connection-query.js","sourceRoot":"","sources":["../../../server/service/connection/connection-query.ts"],"names":[],"mappings":";;;;AAAA,+
|
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;AAG1F,IAAM,eAAe,GAArB,MAAM,eAAe;IAGpB,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,CAAC,CAAC,OAAO,CAAC;YACvD,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE;YAC1C,SAAS,EAAE,CAAC,QAAQ,CAAC;SACtB,CAAC,CAAA;QAEF,OAAO;YACL,GAAG,UAAU;YACb,KAAK,EAAE,sCAAiB,CAAC,qBAAqB,CAAC,UAAU,CAAC;gBACxD,CAAC,CAAC,kCAAgB,CAAC,SAAS;gBAC5B,CAAC,CAAC,kCAAgB,CAAC,YAAY;SACpB,CAAA;IACjB,CAAC;IAIK,AAAN,KAAK,CAAC,WAAW,CACU,MAAiB,EACnC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,MAAM,YAAY,GAAG,IAAA,qCAA6B,EAAC;YACjD,UAAU,EAAE,IAAA,qBAAa,EAAC,4BAAU,CAA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,CAAC,iCAAe,EAAE,EAAE,WAAW,EAAE,oCAAoC,EAAE,CAAC;IACnE,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;4CAA4B,iCAAe;2DAShG;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAClB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;2CAExC;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAChB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;6CAI1C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;8CAE3C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;8CAE3C;0BA/EU,eAAe;IAD3B,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,eAAe,CAgF3B","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@Resolver(Connection)\nexport class ConnectionQuery {\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => Connection, { description: 'To fetch a connection' })\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, { description: 'To fetch multiple connections' })\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: 'To fetch the state of a connection' })\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"]}
|
@@ -20,15 +20,14 @@ exports.ConnectionSubscription = ConnectionSubscription;
|
|
20
20
|
tslib_1.__decorate([
|
21
21
|
(0, type_graphql_1.Subscription)({
|
22
22
|
subscribe: ({ args, context, info }) => {
|
23
|
-
var _a;
|
24
23
|
const { domain, user } = context.state;
|
25
24
|
const { name } = args;
|
26
|
-
const subdomain = domain
|
25
|
+
const subdomain = domain?.subdomain;
|
27
26
|
debug('subscribe', subdomain);
|
28
27
|
if (!domain) {
|
29
28
|
throw new Error('domain required.');
|
30
29
|
}
|
31
|
-
if (!
|
30
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
32
31
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
33
32
|
}
|
34
33
|
process.nextTick(async () => {
|
@@ -42,13 +41,17 @@ tslib_1.__decorate([
|
|
42
41
|
});
|
43
42
|
connections.forEach(connection => {
|
44
43
|
shell_1.pubsub.publish('connection-state', {
|
45
|
-
connectionState:
|
44
|
+
connectionState: {
|
45
|
+
...connection,
|
46
|
+
state: connection_manager_1.ConnectionManager.getConnectionInstance(connection) ? connection_type_1.ConnectionStatus.CONNECTED : connection_type_1.ConnectionStatus.DISCONNECTED,
|
47
|
+
timestamp: new Date()
|
48
|
+
}
|
46
49
|
});
|
47
50
|
});
|
48
51
|
});
|
49
52
|
return (0, graphql_yoga_1.pipe)(shell_1.pubsub.subscribe('connection-state'), (0, graphql_yoga_1.filter)(async (payload) => {
|
50
53
|
const { domain: pdomain, name: pname } = payload.connectionState;
|
51
|
-
return (!name || name === pname) && subdomain ===
|
54
|
+
return (!name || name === pname) && subdomain === pdomain?.subdomain;
|
52
55
|
}));
|
53
56
|
}
|
54
57
|
}),
|
@@ -61,15 +64,14 @@ tslib_1.__decorate([
|
|
61
64
|
tslib_1.__decorate([
|
62
65
|
(0, type_graphql_1.Subscription)({
|
63
66
|
subscribe: ({ args, context, info }) => {
|
64
|
-
var _a;
|
65
67
|
const { domain, user } = context.state;
|
66
68
|
const { level } = args;
|
67
|
-
const subdomain = domain
|
69
|
+
const subdomain = domain?.subdomain;
|
68
70
|
debug('subscribe', subdomain);
|
69
71
|
if (!domain) {
|
70
72
|
throw new Error('domain required');
|
71
73
|
}
|
72
|
-
if (!
|
74
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
73
75
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
74
76
|
}
|
75
77
|
return (0, graphql_yoga_1.pipe)(shell_1.pubsub.subscribe('connection-log'), (0, graphql_yoga_1.filter)(async (payload) => {
|
@@ -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;IAgDjC,eAAe,CAAS,OAA6C,EAAmC,IAAY;QAClH,OAAO,OAAO,CAAC,eAAe,CAAA;IAChC,CAAC;IAuCD,aAAa,CAAS,OAAqB,EAAoC,KAAa;QAC1F,OAAO,OAAO,CAAC,GAAG,CAAA;IACpB,CAAC;CACF,CAAA;AA5FY,wDAAsB;AAgDjC;IA/CC,IAAA,2BAAY,EAAC;QACZ,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE
|
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,KA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uBAAQ,EAAC,4BAAU,CAAC;GACR,sBAAsB,CA4FlC","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 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) ? ConnectionStatus.CONNECTED : 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(@Root() payload: { connectionState: ConnectionState }, @Arg('name', { nullable: true }) name: string): ConnectionState {\n return payload.connectionState\n }\n\n @Subscription({\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"]}
|
@@ -51,8 +51,15 @@ export declare class Connection {
|
|
51
51
|
state: ConnectionStatus;
|
52
52
|
/**
|
53
53
|
* Additional parameters for the connection, stored as a JSON string.
|
54
|
+
*
|
55
|
+
* [Caution]
|
56
|
+
* 이 컬럼타입은 postgres 데이터베이스에서는 varchar 타입을 유지한다.
|
57
|
+
* 이는 데이터베이스 타입을 변경하면 기존 데이터가 손실될 수 있기 때문이다.
|
58
|
+
* 'simple-json' 타입으로 변경 전에 postgres 데이타베이스에 이미 varchar 타입으로 사용한 사례가 많기 때문이다.
|
54
59
|
*/
|
55
|
-
params:
|
60
|
+
params: {
|
61
|
+
[key: string]: any;
|
62
|
+
};
|
56
63
|
/**
|
57
64
|
* The date and time when the connection was created.
|
58
65
|
*/
|
@@ -114,7 +121,9 @@ export declare class NewConnection {
|
|
114
121
|
type?: string;
|
115
122
|
edge?: Appliance;
|
116
123
|
endpoint?: string;
|
117
|
-
params?:
|
124
|
+
params?: {
|
125
|
+
[key: string]: any;
|
126
|
+
};
|
118
127
|
}
|
119
128
|
export declare class ConnectionPatch {
|
120
129
|
id: string;
|
@@ -124,7 +133,9 @@ export declare class ConnectionPatch {
|
|
124
133
|
edge?: Appliance;
|
125
134
|
endpoint?: string;
|
126
135
|
active?: boolean;
|
127
|
-
params?:
|
136
|
+
params?: {
|
137
|
+
[key: string]: any;
|
138
|
+
};
|
128
139
|
cuFlag?: string;
|
129
140
|
}
|
130
141
|
export declare class ConnectionList {
|
@@ -9,6 +9,8 @@ const env_1 = require("@things-factory/env");
|
|
9
9
|
const shell_1 = require("@things-factory/shell");
|
10
10
|
const engine_1 = require("../../engine");
|
11
11
|
const proxy_connector_1 = require("../../engine/connector/proxy-connector");
|
12
|
+
const ORMCONFIG = env_1.config.get('ormconfig', {});
|
13
|
+
const DATABASE_TYPE = ORMCONFIG.type;
|
12
14
|
var ConnectionStatus;
|
13
15
|
(function (ConnectionStatus) {
|
14
16
|
ConnectionStatus["CONNECTED"] = "CONNECTED";
|
@@ -26,14 +28,10 @@ let Connection = class Connection {
|
|
26
28
|
async connect() {
|
27
29
|
const { type, edge } = this;
|
28
30
|
const connector = edge ? proxy_connector_1.ProxyConnector.instance : engine_1.ConnectionManager.getConnector(type);
|
29
|
-
|
30
|
-
|
31
|
-
params
|
32
|
-
}
|
33
|
-
catch (ex) {
|
34
|
-
env_1.logger.error(`connection '${this.name}' params should be JSON format`, ex);
|
35
|
-
}
|
36
|
-
await connector.connect(Object.assign(Object.assign({}, this), { params }));
|
31
|
+
await connector.connect({
|
32
|
+
...this,
|
33
|
+
params: this.params || {}
|
34
|
+
});
|
37
35
|
}
|
38
36
|
/**
|
39
37
|
* @brief Asynchronous method to disconnect the connection.
|
@@ -113,9 +111,25 @@ tslib_1.__decorate([
|
|
113
111
|
tslib_1.__metadata("design:type", String)
|
114
112
|
], Connection.prototype, "state", void 0);
|
115
113
|
tslib_1.__decorate([
|
116
|
-
(0, typeorm_1.Column)({
|
117
|
-
|
118
|
-
|
114
|
+
(0, typeorm_1.Column)({
|
115
|
+
type: DATABASE_TYPE == 'postgres' ? 'varchar' : 'simple-json',
|
116
|
+
nullable: true,
|
117
|
+
transformer: DATABASE_TYPE == 'postgres'
|
118
|
+
? {
|
119
|
+
to: (value) => JSON.stringify(value),
|
120
|
+
from: (value) => {
|
121
|
+
try {
|
122
|
+
return JSON.parse(value);
|
123
|
+
}
|
124
|
+
catch (error) {
|
125
|
+
return null;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
: undefined
|
130
|
+
}),
|
131
|
+
(0, type_graphql_1.Field)(type => shell_1.ScalarObject, { nullable: true }),
|
132
|
+
tslib_1.__metadata("design:type", Object)
|
119
133
|
], Connection.prototype, "params", void 0);
|
120
134
|
tslib_1.__decorate([
|
121
135
|
(0, typeorm_1.CreateDateColumn)(),
|
@@ -229,8 +243,8 @@ tslib_1.__decorate([
|
|
229
243
|
tslib_1.__metadata("design:type", String)
|
230
244
|
], NewConnection.prototype, "endpoint", void 0);
|
231
245
|
tslib_1.__decorate([
|
232
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
233
|
-
tslib_1.__metadata("design:type",
|
246
|
+
(0, type_graphql_1.Field)(type => shell_1.ScalarObject, { nullable: true }),
|
247
|
+
tslib_1.__metadata("design:type", Object)
|
234
248
|
], NewConnection.prototype, "params", void 0);
|
235
249
|
exports.NewConnection = NewConnection = tslib_1.__decorate([
|
236
250
|
(0, type_graphql_1.InputType)()
|
@@ -267,8 +281,8 @@ tslib_1.__decorate([
|
|
267
281
|
tslib_1.__metadata("design:type", Boolean)
|
268
282
|
], ConnectionPatch.prototype, "active", void 0);
|
269
283
|
tslib_1.__decorate([
|
270
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
271
|
-
tslib_1.__metadata("design:type",
|
284
|
+
(0, type_graphql_1.Field)(type => shell_1.ScalarObject, { nullable: true }),
|
285
|
+
tslib_1.__metadata("design:type", Object)
|
272
286
|
], ConnectionPatch.prototype, "params", void 0);
|
273
287
|
tslib_1.__decorate([
|
274
288
|
(0, type_graphql_1.Field)({ nullable: true }),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"connection-type.js","sourceRoot":"","sources":["../../../server/service/connection/connection-type.ts"],"names":[],"mappings":";;;;AAAA,+CAAsF;AACtF,qCASgB;AAEhB,yDAA2D;AAC3D,6CAA4C;AAC5C,iDAAyD;AAEzD,yCAAgD;AAChD,4EAAuE;AAEvE,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,2CAAu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AC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;;6CACT;AAGnB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,CAAC;;6CACN;yBALF,cAAc;IAD1B,IAAA,yBAAU,GAAE;GACA,cAAc,CAM1B","sourcesContent":["import { Field, ID, InputType, Int, ObjectType, registerEnumType } from 'type-graphql'\nimport {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\n\nimport { User, Appliance } from '@things-factory/auth-base'\nimport { logger } from '@things-factory/env'\nimport { Domain, ObjectRef } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine'\nimport { ProxyConnector } from '../../engine/connector/proxy-connector'\n\nexport enum ConnectionStatus {\n CONNECTED = 'CONNECTED',\n DISCONNECTED = 'DISCONNECTED'\n}\n\nregisterEnumType(ConnectionStatus, {\n name: 'ConnectionStatus',\n description: 'state enumeration of a connection'\n})\n\n@Entity()\n@Index('ix_connection_0', (connection: Connection) => [connection.domain, connection.name], { unique: true })\n@ObjectType()\nexport class Connection {\n /**\n * Unique identifier for the connection, generated in UUID format.\n */\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n readonly id: string\n\n /**\n * Many-to-One relationship with the Domain entity.\n */\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true })\n domain: Domain\n\n /**\n * Stores the ID of the associated Domain.\n */\n @RelationId((connection: Connection) => connection.domain)\n domainId: string\n\n /**\n * The name of the connection.\n */\n @Column()\n @Field()\n name: string\n\n /**\n * Optional description for the connection.\n */\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n description: string\n\n /**\n * The type of the connection.\n */\n @Column()\n @Field({ nullable: true })\n type: string\n\n /**\n * Many-to-One relationship with the Appliance entity which delegate the connection. Optional field.\n */\n @ManyToOne(type => Appliance, { nullable: true })\n @Field({ nullable: true })\n edge: Appliance\n\n /**\n * Stores the ID of the Appliance who delegate the connection.\n */\n @RelationId((connection: Connection) => connection.edge)\n edgeId: string\n\n /**\n * The endpoint for the connection.\n */\n @Column()\n @Field({ nullable: true })\n endpoint: string\n\n /**\n * Indicates the active status of the connection.\n */\n @Column({ nullable: true })\n @Field({ nullable: true })\n active: boolean\n\n /**\n * The status of the connection, using the ConnectionStatus type.\n */\n @Field({ nullable: true })\n state: ConnectionStatus\n\n /**\n * Additional parameters for the connection, stored as a JSON string.\n */\n @Column({ nullable: true })\n @Field({ nullable: true })\n params: string\n\n /**\n * The date and time when the connection was created.\n */\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt: Date\n\n /**\n * The date and time when the connection was last updated.\n */\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt: Date\n\n /**\n * Many-to-One relationship with the User entity who created the connection. Optional field.\n */\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n creator: User\n\n /**\n * Stores the ID of the User who created the connection.\n */\n @RelationId((connection: Connection) => connection.creator)\n creatorId: string\n\n /**\n * Many-to-One relationship with the User entity who last updated the connection.\n * Optional field.\n */\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n updater: User\n\n /**\n * Stores the ID of the User who last updated the connection.\n *\n */\n @RelationId((connection: Connection) => connection.updater)\n updaterId: string\n\n /**\n * Asynchronous method to establish the connection.\n *\n */\n async connect() {\n const { type, edge } = this\n const connector = edge ? ProxyConnector.instance : ConnectionManager.getConnector(type)\n var params = {}\n\n try {\n params = JSON.parse(this.params || '{}')\n } catch (ex) {\n logger.error(`connection '${this.name}' params should be JSON format`, ex)\n }\n\n await connector.connect({\n ...this,\n params\n })\n }\n\n /**\n * @brief Asynchronous method to disconnect the connection.\n *\n */\n async disconnect() {\n try {\n const { type, edge } = this\n const connector = edge ? ProxyConnector.instance : ConnectionManager.getConnector(type)\n await connector.disconnect(this)\n } finally {\n }\n }\n}\n\n/**\n * Connection의 params의 원 타입과 사용 시에 타입 불일치로 인해 임시적으로 생성한 타입으로\n * 추후, 타입 일치를 통해서 제거할 예정임.\n *\n */\nexport interface InputConnection extends Connection {\n params: any\n}\n\n@ObjectType()\nexport class ConnectionState {\n @Field(type => Domain)\n domain?: Domain\n\n @Field({ nullable: true })\n id?: string\n\n @Field({ nullable: true })\n name?: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field({ nullable: true })\n type?: string\n\n @Field(type => Appliance, { nullable: true })\n edge?: Appliance\n\n @Field({ nullable: true })\n state?: ConnectionStatus\n\n @Field({ nullable: true })\n timestamp?: Date\n}\n\n@InputType()\nexport class NewConnection {\n @Field()\n name: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field({ nullable: true })\n type?: string\n\n @Field(type => ObjectRef, { nullable: true })\n edge?: Appliance\n\n @Field({ nullable: true })\n endpoint?: string\n\n @Field({ nullable: true })\n params?: string\n}\n\n@InputType()\nexport class ConnectionPatch {\n @Field(type => ID, { nullable: true })\n id: string\n\n @Field({ nullable: true })\n name?: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field({ nullable: true })\n type?: string\n\n @Field(type => ObjectRef, { nullable: true })\n edge?: Appliance\n\n @Field({ nullable: true })\n endpoint?: string\n\n @Field({ nullable: true })\n active?: boolean\n\n @Field({ nullable: true })\n params?: string\n\n @Field({ nullable: true })\n cuFlag?: string\n}\n\n@ObjectType()\nexport class ConnectionList {\n @Field(type => [Connection])\n items: Connection[]\n\n @Field(type => Int)\n total: number\n}\n"]}
|
1
|
+
{"version":3,"file":"connection-type.js","sourceRoot":"","sources":["../../../server/service/connection/connection-type.ts"],"names":[],"mappings":";;;;AAAA,+CAAsF;AACtF,qCASgB;AAEhB,yDAA2D;AAC3D,6CAA4C;AAC5C,iDAAuE;AAEvE,yCAAgD;AAChD,4EAAuE;AAEvE,MAAM,SAAS,GAAG,YAAM,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAA;AAEpC,IAAY,gBAGX;AA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EAAE,IAAI,EAAE,CAAC;;+CACV;AAGhB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,oBAAY,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;+CACjB;AAG/B;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;+CACX;0BA1BJ,eAAe;IAD3B,IAAA,wBAAS,GAAE;GACC,eAAe,CA2B3B;AAGM,IAAM,cAAc,GAApB,MAAM,cAAc;CAM1B,CAAA;AANY,wCAAc;AAEzB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;;6CACT;AAGnB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,CAAC;;6CACN;yBALF,cAAc;IAD1B,IAAA,yBAAU,GAAE;GACA,cAAc,CAM1B","sourcesContent":["import { Field, ID, InputType, Int, ObjectType, registerEnumType } from 'type-graphql'\nimport {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\n\nimport { User, Appliance } from '@things-factory/auth-base'\nimport { config } from '@things-factory/env'\nimport { Domain, ObjectRef, ScalarObject } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine'\nimport { ProxyConnector } from '../../engine/connector/proxy-connector'\n\nconst ORMCONFIG = config.get('ormconfig', {})\nconst DATABASE_TYPE = ORMCONFIG.type\n\nexport enum ConnectionStatus {\n CONNECTED = 'CONNECTED',\n DISCONNECTED = 'DISCONNECTED'\n}\n\nregisterEnumType(ConnectionStatus, {\n name: 'ConnectionStatus',\n description: 'state enumeration of a connection'\n})\n\n@Entity()\n@Index('ix_connection_0', (connection: Connection) => [connection.domain, connection.name], { unique: true })\n@ObjectType()\nexport class Connection {\n /**\n * Unique identifier for the connection, generated in UUID format.\n */\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n readonly id: string\n\n /**\n * Many-to-One relationship with the Domain entity.\n */\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true })\n domain: Domain\n\n /**\n * Stores the ID of the associated Domain.\n */\n @RelationId((connection: Connection) => connection.domain)\n domainId: string\n\n /**\n * The name of the connection.\n */\n @Column()\n @Field()\n name: string\n\n /**\n * Optional description for the connection.\n */\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n description: string\n\n /**\n * The type of the connection.\n */\n @Column()\n @Field({ nullable: true })\n type: string\n\n /**\n * Many-to-One relationship with the Appliance entity which delegate the connection. Optional field.\n */\n @ManyToOne(type => Appliance, { nullable: true })\n @Field({ nullable: true })\n edge: Appliance\n\n /**\n * Stores the ID of the Appliance who delegate the connection.\n */\n @RelationId((connection: Connection) => connection.edge)\n edgeId: string\n\n /**\n * The endpoint for the connection.\n */\n @Column()\n @Field({ nullable: true })\n endpoint: string\n\n /**\n * Indicates the active status of the connection.\n */\n @Column({ nullable: true })\n @Field({ nullable: true })\n active: boolean\n\n /**\n * The status of the connection, using the ConnectionStatus type.\n */\n @Field({ nullable: true })\n state: ConnectionStatus\n\n /**\n * Additional parameters for the connection, stored as a JSON string.\n *\n * [Caution]\n * 이 컬럼타입은 postgres 데이터베이스에서는 varchar 타입을 유지한다.\n * 이는 데이터베이스 타입을 변경하면 기존 데이터가 손실될 수 있기 때문이다.\n * 'simple-json' 타입으로 변경 전에 postgres 데이타베이스에 이미 varchar 타입으로 사용한 사례가 많기 때문이다.\n */\n @Column({\n type: DATABASE_TYPE == 'postgres' ? 'varchar' : 'simple-json',\n nullable: true,\n transformer:\n DATABASE_TYPE == 'postgres'\n ? {\n to: (value: any) => JSON.stringify(value),\n from: (value: string) => {\n try {\n return JSON.parse(value)\n } catch (error) {\n return null\n }\n }\n }\n : undefined\n })\n @Field(type => ScalarObject, { nullable: true })\n params: { [key: string]: any }\n\n /**\n * The date and time when the connection was created.\n */\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt: Date\n\n /**\n * The date and time when the connection was last updated.\n */\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt: Date\n\n /**\n * Many-to-One relationship with the User entity who created the connection. Optional field.\n */\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n creator: User\n\n /**\n * Stores the ID of the User who created the connection.\n */\n @RelationId((connection: Connection) => connection.creator)\n creatorId: string\n\n /**\n * Many-to-One relationship with the User entity who last updated the connection.\n * Optional field.\n */\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n updater: User\n\n /**\n * Stores the ID of the User who last updated the connection.\n *\n */\n @RelationId((connection: Connection) => connection.updater)\n updaterId: string\n\n /**\n * Asynchronous method to establish the connection.\n *\n */\n async connect() {\n const { type, edge } = this\n const connector = edge ? ProxyConnector.instance : ConnectionManager.getConnector(type)\n\n await connector.connect({\n ...this,\n params: this.params || {}\n })\n }\n\n /**\n * @brief Asynchronous method to disconnect the connection.\n *\n */\n async disconnect() {\n try {\n const { type, edge } = this\n const connector = edge ? ProxyConnector.instance : ConnectionManager.getConnector(type)\n await connector.disconnect(this)\n } finally {\n }\n }\n}\n\n/**\n * Connection의 params의 원 타입과 사용 시에 타입 불일치로 인해 임시적으로 생성한 타입으로\n * 추후, 타입 일치를 통해서 제거할 예정임.\n *\n */\nexport interface InputConnection extends Connection {\n params: any\n}\n\n@ObjectType()\nexport class ConnectionState {\n @Field(type => Domain)\n domain?: Domain\n\n @Field({ nullable: true })\n id?: string\n\n @Field({ nullable: true })\n name?: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field({ nullable: true })\n type?: string\n\n @Field(type => Appliance, { nullable: true })\n edge?: Appliance\n\n @Field({ nullable: true })\n state?: ConnectionStatus\n\n @Field({ nullable: true })\n timestamp?: Date\n}\n\n@InputType()\nexport class NewConnection {\n @Field()\n name: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field({ nullable: true })\n type?: string\n\n @Field(type => ObjectRef, { nullable: true })\n edge?: Appliance\n\n @Field({ nullable: true })\n endpoint?: string\n\n @Field(type => ScalarObject, { nullable: true })\n params?: { [key: string]: any }\n}\n\n@InputType()\nexport class ConnectionPatch {\n @Field(type => ID, { nullable: true })\n id: string\n\n @Field({ nullable: true })\n name?: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field({ nullable: true })\n type?: string\n\n @Field(type => ObjectRef, { nullable: true })\n edge?: Appliance\n\n @Field({ nullable: true })\n endpoint?: string\n\n @Field({ nullable: true })\n active?: boolean\n\n @Field(type => ScalarObject, { nullable: true })\n params?: { [key: string]: any }\n\n @Field({ nullable: true })\n cuFlag?: string\n}\n\n@ObjectType()\nexport class ConnectionList {\n @Field(type => [Connection])\n items: Connection[]\n\n @Field(type => Int)\n total: number\n}\n"]}
|