@things-factory/integration-base 9.0.0-beta.8 → 9.0.0
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/analysis/analysis-query.d.ts +3 -0
- package/dist-server/service/analysis/analysis-query.js +6 -1
- package/dist-server/service/analysis/analysis-query.js.map +1 -1
- package/dist-server/service/connection/connection-mutation.d.ts +3 -1
- package/dist-server/service/connection/connection-mutation.js +69 -21
- package/dist-server/service/connection/connection-mutation.js.map +1 -1
- package/dist-server/service/connection/connection-query.d.ts +3 -0
- package/dist-server/service/connection/connection-query.js +22 -6
- package/dist-server/service/connection/connection-query.js.map +1 -1
- package/dist-server/service/connection/connection-subscription.js +14 -8
- package/dist-server/service/connection/connection-subscription.js.map +1 -1
- package/dist-server/service/connection/connection-type.d.ts +15 -4
- package/dist-server/service/connection/connection-type.js +78 -58
- package/dist-server/service/connection/connection-type.js.map +1 -1
- package/dist-server/service/connector/connector-query.d.ts +4 -1
- package/dist-server/service/connector/connector-query.js +8 -5
- package/dist-server/service/connector/connector-query.js.map +1 -1
- package/dist-server/service/connector/connector-type.js +12 -9
- package/dist-server/service/connector/connector-type.js.map +1 -1
- package/dist-server/service/payload-log/payload-log-mutation.js +30 -12
- package/dist-server/service/payload-log/payload-log-mutation.js.map +1 -1
- package/dist-server/service/payload-log/payload-log-query.d.ts +3 -0
- package/dist-server/service/payload-log/payload-log-query.js +5 -2
- package/dist-server/service/payload-log/payload-log-query.js.map +1 -1
- package/dist-server/service/payload-log/payload-log-type.js +11 -11
- package/dist-server/service/payload-log/payload-log-type.js.map +1 -1
- package/dist-server/service/payload-log/payload-log.d.ts +1 -1
- package/dist-server/service/payload-log/payload-log.js +18 -14
- package/dist-server/service/payload-log/payload-log.js.map +1 -1
- package/dist-server/service/property-spec.js +12 -7
- package/dist-server/service/property-spec.js.map +1 -1
- package/dist-server/service/scenario/scenario-mutation.js +71 -26
- package/dist-server/service/scenario/scenario-mutation.js.map +1 -1
- package/dist-server/service/scenario/scenario-query.d.ts +3 -0
- package/dist-server/service/scenario/scenario-query.js +7 -5
- package/dist-server/service/scenario/scenario-query.js.map +1 -1
- package/dist-server/service/scenario/scenario-type.js +27 -24
- package/dist-server/service/scenario/scenario-type.js.map +1 -1
- package/dist-server/service/scenario/scenario.js +27 -24
- package/dist-server/service/scenario/scenario.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-mutation.js +8 -3
- package/dist-server/service/scenario-instance/scenario-instance-mutation.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-query.d.ts +3 -0
- package/dist-server/service/scenario-instance/scenario-instance-query.js +5 -2
- package/dist-server/service/scenario-instance/scenario-instance-query.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-subscription.js +10 -9
- package/dist-server/service/scenario-instance/scenario-instance-subscription.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-type.js +76 -71
- package/dist-server/service/scenario-instance/scenario-instance-type.js.map +1 -1
- package/dist-server/service/scenario-queue/scenario-queue-subscription.js +4 -4
- package/dist-server/service/scenario-queue/scenario-queue-subscription.js.map +1 -1
- package/dist-server/service/scenario-queue/scenario-queue-type.js +8 -8
- package/dist-server/service/scenario-queue/scenario-queue-type.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 +41 -16
- package/dist-server/service/state-register/state-register-mutation.js.map +1 -1
- package/dist-server/service/state-register/state-register-query.d.ts +3 -0
- package/dist-server/service/state-register/state-register-query.js +7 -4
- package/dist-server/service/state-register/state-register-query.js.map +1 -1
- package/dist-server/service/state-register/state-register-type.js +3 -3
- package/dist-server/service/state-register/state-register-type.js.map +1 -1
- package/dist-server/service/state-register/state-register.js +4 -2
- package/dist-server/service/state-register/state-register.js.map +1 -1
- package/dist-server/service/step/step-mutation.js +13 -5
- package/dist-server/service/step/step-mutation.js.map +1 -1
- package/dist-server/service/step/step-query.d.ts +3 -0
- package/dist-server/service/step/step-query.js +5 -2
- package/dist-server/service/step/step-query.js.map +1 -1
- package/dist-server/service/step/step-type.d.ts +11 -3
- package/dist-server/service/step/step-type.js +54 -35
- package/dist-server/service/step/step-type.js.map +1 -1
- package/dist-server/service/task-type/task-type-query.js +5 -3
- package/dist-server/service/task-type/task-type-query.js.map +1 -1
- package/dist-server/service/task-type/task-type-type.js +12 -9
- package/dist-server/service/task-type/task-type-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 +12 -12
- 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,7 +143,8 @@ let ConnectionMutation = class ConnectionMutation {
|
|
105
143
|
exports.ConnectionMutation = ConnectionMutation;
|
106
144
|
tslib_1.__decorate([
|
107
145
|
(0, type_graphql_1.Directive)('@transaction'),
|
108
|
-
(0, type_graphql_1.
|
146
|
+
(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.' }),
|
109
148
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('connection')),
|
110
149
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
111
150
|
tslib_1.__metadata("design:type", Function),
|
@@ -114,7 +153,8 @@ tslib_1.__decorate([
|
|
114
153
|
], ConnectionMutation.prototype, "createConnection", null);
|
115
154
|
tslib_1.__decorate([
|
116
155
|
(0, type_graphql_1.Directive)('@transaction'),
|
117
|
-
(0, type_graphql_1.
|
156
|
+
(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.' }),
|
118
158
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
119
159
|
tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
|
120
160
|
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
@@ -124,7 +164,8 @@ tslib_1.__decorate([
|
|
124
164
|
], ConnectionMutation.prototype, "updateConnection", null);
|
125
165
|
tslib_1.__decorate([
|
126
166
|
(0, type_graphql_1.Directive)('@transaction'),
|
127
|
-
(0, type_graphql_1.
|
167
|
+
(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.' }),
|
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)()),
|
130
171
|
tslib_1.__metadata("design:type", Function),
|
@@ -133,7 +174,8 @@ tslib_1.__decorate([
|
|
133
174
|
], ConnectionMutation.prototype, "updateMultipleConnection", null);
|
134
175
|
tslib_1.__decorate([
|
135
176
|
(0, type_graphql_1.Directive)('@transaction'),
|
136
|
-
(0, type_graphql_1.
|
177
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
178
|
+
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'Deletes a single connection by its name.' }),
|
137
179
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
138
180
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
139
181
|
tslib_1.__metadata("design:type", Function),
|
@@ -142,7 +184,8 @@ tslib_1.__decorate([
|
|
142
184
|
], ConnectionMutation.prototype, "deleteConnection", null);
|
143
185
|
tslib_1.__decorate([
|
144
186
|
(0, type_graphql_1.Directive)('@transaction'),
|
145
|
-
(0, type_graphql_1.
|
187
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
188
|
+
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'Deletes multiple connections by their names.' }),
|
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)()),
|
148
191
|
tslib_1.__metadata("design:type", Function),
|
@@ -150,7 +193,9 @@ tslib_1.__decorate([
|
|
150
193
|
tslib_1.__metadata("design:returntype", Promise)
|
151
194
|
], ConnectionMutation.prototype, "deleteConnections", null);
|
152
195
|
tslib_1.__decorate([
|
153
|
-
(0, type_graphql_1.
|
196
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
197
|
+
(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.' }),
|
154
199
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
155
200
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
156
201
|
tslib_1.__metadata("design:type", Function),
|
@@ -158,7 +203,9 @@ tslib_1.__decorate([
|
|
158
203
|
tslib_1.__metadata("design:returntype", Promise)
|
159
204
|
], ConnectionMutation.prototype, "connectConnection", null);
|
160
205
|
tslib_1.__decorate([
|
161
|
-
(0, type_graphql_1.
|
206
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
207
|
+
(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.' }),
|
162
209
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
163
210
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
164
211
|
tslib_1.__metadata("design:type", Function),
|
@@ -166,10 +213,11 @@ 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
|
-
,
|
172
|
-
|
216
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
217
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
|
218
|
+
(0, type_graphql_1.Mutation)(returns => Boolean, {
|
219
|
+
description: 'Imports multiple connections. Can overwrite existing connections if IDs or names match.'
|
220
|
+
}),
|
173
221
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('connections', type => [connection_type_1.ConnectionPatch])),
|
174
222
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
175
223
|
tslib_1.__metadata("design:type", Function),
|
@@ -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,OAAwB;QAClG,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,4BAAU,CAAC,CAAC,IAAI,iCACzC,UAAU,KACb,MAAM,EACN,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,IAAI,IACb,CAAA;IACJ,CAAC;IAIK,AAAN,KAAK,CAAC,gBAAgB,CAAc,IAAY,EAAgB,KAAsB,EAAS,OAAwB;QACrH,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,4BAAU,CAAC,CAAA;QAC/C,MAAM,UAAU,GAAG,MAAM,U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\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,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,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,4BAAU,CAAC,CAAA;QAC/C,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC1C,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,E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AA,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,6 +1,9 @@
|
|
1
1
|
import { Appliance, User } from '@things-factory/auth-base';
|
2
2
|
import { Domain, ListParam } from '@things-factory/shell';
|
3
3
|
import { Connection, ConnectionList, ConnectionState } from './connection-type';
|
4
|
+
/**
|
5
|
+
* @description Provides GraphQL resolvers for the Connection entity.
|
6
|
+
*/
|
4
7
|
export declare class ConnectionQuery {
|
5
8
|
connection(name: string, context: ResolverContext): Promise<Connection>;
|
6
9
|
connections(params: ListParam, context: ResolverContext): Promise<ConnectionList>;
|
@@ -7,6 +7,9 @@ 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
9
|
const connection_type_1 = require("./connection-type");
|
10
|
+
/**
|
11
|
+
* @description Provides GraphQL resolvers for the Connection entity.
|
12
|
+
*/
|
10
13
|
let ConnectionQuery = class ConnectionQuery {
|
11
14
|
async connection(name, context) {
|
12
15
|
const { domain } = context.state;
|
@@ -14,9 +17,12 @@ let ConnectionQuery = class ConnectionQuery {
|
|
14
17
|
where: { domain: { id: domain.id }, name },
|
15
18
|
relations: ['domain']
|
16
19
|
});
|
17
|
-
return
|
20
|
+
return {
|
21
|
+
...connection,
|
22
|
+
state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
|
18
23
|
? connection_type_1.ConnectionStatus.CONNECTED
|
19
|
-
: connection_type_1.ConnectionStatus.DISCONNECTED
|
24
|
+
: connection_type_1.ConnectionStatus.DISCONNECTED
|
25
|
+
};
|
20
26
|
}
|
21
27
|
async connections(params, context) {
|
22
28
|
const { domain } = context.state;
|
@@ -38,7 +44,10 @@ let ConnectionQuery = class ConnectionQuery {
|
|
38
44
|
fetchConnectionState(name, context) {
|
39
45
|
const { domain } = context.state;
|
40
46
|
const connection = connection_manager_1.ConnectionManager.getConnectionInstanceEntityByName(domain, name);
|
41
|
-
return
|
47
|
+
return {
|
48
|
+
...connection,
|
49
|
+
state: connection ? connection_type_1.ConnectionStatus.CONNECTED : connection_type_1.ConnectionStatus.DISCONNECTED
|
50
|
+
};
|
42
51
|
}
|
43
52
|
async edge(connection) {
|
44
53
|
return connection.edgeId && (await (0, shell_1.getRepository)(auth_base_1.Appliance).findOneBy({ id: connection.edgeId }));
|
@@ -55,7 +64,10 @@ let ConnectionQuery = class ConnectionQuery {
|
|
55
64
|
};
|
56
65
|
exports.ConnectionQuery = ConnectionQuery;
|
57
66
|
tslib_1.__decorate([
|
58
|
-
(0, type_graphql_1.
|
67
|
+
(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
|
+
description: 'Fetches a single connection by its name, including its current state.'
|
70
|
+
}),
|
59
71
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
60
72
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
61
73
|
tslib_1.__metadata("design:type", Function),
|
@@ -63,7 +75,10 @@ tslib_1.__decorate([
|
|
63
75
|
tslib_1.__metadata("design:returntype", Promise)
|
64
76
|
], ConnectionQuery.prototype, "connection", null);
|
65
77
|
tslib_1.__decorate([
|
66
|
-
(0, type_graphql_1.
|
78
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
|
79
|
+
(0, type_graphql_1.Query)(returns => connection_type_1.ConnectionList, {
|
80
|
+
description: 'Fetches a paginated list of connections, including their current states.'
|
81
|
+
}),
|
67
82
|
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
68
83
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
69
84
|
tslib_1.__metadata("design:type", Function),
|
@@ -71,7 +86,8 @@ tslib_1.__decorate([
|
|
71
86
|
tslib_1.__metadata("design:returntype", Promise)
|
72
87
|
], ConnectionQuery.prototype, "connections", null);
|
73
88
|
tslib_1.__decorate([
|
74
|
-
(0, type_graphql_1.
|
89
|
+
(0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
|
90
|
+
(0, type_graphql_1.Query)(returns => connection_type_1.ConnectionState, { description: 'Fetches the current state of a single connection by its name.' }),
|
75
91
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
|
76
92
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
77
93
|
tslib_1.__metadata("design:type", Function),
|
@@ -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;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,CAAC,CAAC,OAAO,CAAC;YACvD,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE;YAC1C,SAAS,EAAE,CAAC,QA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ldResolver, 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"]}
|
@@ -19,16 +19,16 @@ let ConnectionSubscription = class ConnectionSubscription {
|
|
19
19
|
exports.ConnectionSubscription = ConnectionSubscription;
|
20
20
|
tslib_1.__decorate([
|
21
21
|
(0, type_graphql_1.Subscription)({
|
22
|
+
description: 'Subscribes to the state changes of connections.',
|
22
23
|
subscribe: ({ args, context, info }) => {
|
23
|
-
var _a;
|
24
24
|
const { domain, user } = context.state;
|
25
25
|
const { name } = args;
|
26
|
-
const subdomain = domain
|
26
|
+
const subdomain = domain?.subdomain;
|
27
27
|
debug('subscribe', subdomain);
|
28
28
|
if (!domain) {
|
29
29
|
throw new Error('domain required.');
|
30
30
|
}
|
31
|
-
if (!
|
31
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
32
32
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
33
33
|
}
|
34
34
|
process.nextTick(async () => {
|
@@ -42,13 +42,19 @@ tslib_1.__decorate([
|
|
42
42
|
});
|
43
43
|
connections.forEach(connection => {
|
44
44
|
shell_1.pubsub.publish('connection-state', {
|
45
|
-
connectionState:
|
45
|
+
connectionState: {
|
46
|
+
...connection,
|
47
|
+
state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
|
48
|
+
? connection_type_1.ConnectionStatus.CONNECTED
|
49
|
+
: connection_type_1.ConnectionStatus.DISCONNECTED,
|
50
|
+
timestamp: new Date()
|
51
|
+
}
|
46
52
|
});
|
47
53
|
});
|
48
54
|
});
|
49
55
|
return (0, graphql_yoga_1.pipe)(shell_1.pubsub.subscribe('connection-state'), (0, graphql_yoga_1.filter)(async (payload) => {
|
50
56
|
const { domain: pdomain, name: pname } = payload.connectionState;
|
51
|
-
return (!name || name === pname) && subdomain ===
|
57
|
+
return (!name || name === pname) && subdomain === pdomain?.subdomain;
|
52
58
|
}));
|
53
59
|
}
|
54
60
|
}),
|
@@ -60,16 +66,16 @@ tslib_1.__decorate([
|
|
60
66
|
], ConnectionSubscription.prototype, "connectionState", null);
|
61
67
|
tslib_1.__decorate([
|
62
68
|
(0, type_graphql_1.Subscription)({
|
69
|
+
description: 'Subscribes to log messages from connections.',
|
63
70
|
subscribe: ({ args, context, info }) => {
|
64
|
-
var _a;
|
65
71
|
const { domain, user } = context.state;
|
66
72
|
const { level } = args;
|
67
|
-
const subdomain = domain
|
73
|
+
const subdomain = domain?.subdomain;
|
68
74
|
debug('subscribe', subdomain);
|
69
75
|
if (!domain) {
|
70
76
|
throw new Error('domain required');
|
71
77
|
}
|
72
|
-
if (!
|
78
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
73
79
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
74
80
|
}
|
75
81
|
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;
|
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;YACrB,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,CAAA;YAEnC,KAAK,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;YAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;YACrC,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAA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AA;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,7 +1,7 @@
|
|
1
1
|
import { User, Appliance } from '@things-factory/auth-base';
|
2
2
|
import { Domain } from '@things-factory/shell';
|
3
3
|
export declare enum ConnectionStatus {
|
4
|
-
CONNECTED = "CONNECTED",
|
4
|
+
CONNECTED = "CONNECTED",// Represents an active, established connection.
|
5
5
|
DISCONNECTED = "DISCONNECTED"
|
6
6
|
}
|
7
7
|
export declare class Connection {
|
@@ -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 {
|