@things-factory/integration-base 10.1.119 → 10.1.120

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.
@@ -0,0 +1,16 @@
1
+ import { EntityManager } from 'typeorm';
2
+ import { Domain } from '@things-factory/shell';
3
+ /**
4
+ * A connection's per-domain values live in EnvVars named after it — `Connection::<name>::<key>` (an account, a
5
+ * secret). Renaming the connection carries them along: otherwise the connection, under its new name, finds no
6
+ * account, and nothing on the screen says why.
7
+ *
8
+ * Only the names change; the values are not read or rewritten. A name the new one would take that is already
9
+ * there is refused by name — one of the two would be lost.
10
+ */
11
+ export declare class ConnectionEnvVarCollision extends Error {
12
+ code: string;
13
+ constructor(names: string[]);
14
+ }
15
+ export declare const connectionEnvVarPrefix: (name: string) => string;
16
+ export declare function carryConnectionEnvVars(tx: EntityManager, domain: Domain, from: string, to: string): Promise<string[]>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.connectionEnvVarPrefix = exports.ConnectionEnvVarCollision = void 0;
4
+ exports.carryConnectionEnvVars = carryConnectionEnvVars;
5
+ const typeorm_1 = require("typeorm");
6
+ const shell_1 = require("@things-factory/shell");
7
+ /**
8
+ * A connection's per-domain values live in EnvVars named after it — `Connection::<name>::<key>` (an account, a
9
+ * secret). Renaming the connection carries them along: otherwise the connection, under its new name, finds no
10
+ * account, and nothing on the screen says why.
11
+ *
12
+ * Only the names change; the values are not read or rewritten. A name the new one would take that is already
13
+ * there is refused by name — one of the two would be lost.
14
+ */
15
+ class ConnectionEnvVarCollision extends Error {
16
+ constructor(names) {
17
+ super(`connection-env-var-collision: ${names.join(', ')} already exist — the renamed connection's values cannot take those names`);
18
+ this.code = 'connection-env-var-collision';
19
+ }
20
+ }
21
+ exports.ConnectionEnvVarCollision = ConnectionEnvVarCollision;
22
+ const connectionEnvVarPrefix = (name) => `Connection::${name}::`;
23
+ exports.connectionEnvVarPrefix = connectionEnvVarPrefix;
24
+ async function carryConnectionEnvVars(tx, domain, from, to) {
25
+ if (!from || !to || from === to)
26
+ return [];
27
+ const repository = tx.getRepository(shell_1.EnvVar);
28
+ const oldPrefix = (0, exports.connectionEnvVarPrefix)(from);
29
+ const newPrefix = (0, exports.connectionEnvVarPrefix)(to);
30
+ /* LIKE narrows; the exact prefix decides — a `_` or `%` in a name is a wildcard to LIKE */
31
+ const rows = (await repository.find({ where: { domain: { id: domain.id }, name: (0, typeorm_1.Like)(`Connection::%`) } })).filter(row => row.name.startsWith(oldPrefix));
32
+ if (!rows.length)
33
+ return [];
34
+ const wanted = rows.map(row => newPrefix + row.name.slice(oldPrefix.length));
35
+ const taken = (await repository.find({ where: { domain: { id: domain.id }, name: (0, typeorm_1.Like)(`Connection::%`) } }))
36
+ .map(row => row.name)
37
+ .filter(name => wanted.includes(name));
38
+ if (taken.length)
39
+ throw new ConnectionEnvVarCollision(taken);
40
+ for (const [i, row] of rows.entries()) {
41
+ await repository.update({ id: row.id }, { name: wanted[i] });
42
+ }
43
+ return wanted;
44
+ }
45
+ //# sourceMappingURL=connection-env-vars.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-env-vars.js","sourceRoot":"","sources":["../../../server/service/connection/connection-env-vars.ts"],"names":[],"mappings":";;;AAqBA,wDAsBC;AA3CD,qCAA6C;AAE7C,iDAAsD;AAEtD;;;;;;;GAOG;AACH,MAAa,yBAA0B,SAAQ,KAAK;IAElD,YAAY,KAAe;QACzB,KAAK,CAAC,iCAAiC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAA;QAFpI,SAAI,GAAG,8BAA8B,CAAA;IAGrC,CAAC;CACF;AALD,8DAKC;AAEM,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,eAAe,IAAI,IAAI,CAAA;AAAlE,QAAA,sBAAsB,0BAA4C;AAExE,KAAK,UAAU,sBAAsB,CAAC,EAAiB,EAAE,MAAc,EAA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I,KAAK,CAAC,MAAM;QAAE,MAAM,IAAI,yBAAyB,CAAC,KAAK,CAAC,CAAA;IAE5D,KAAK,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QACtC,MAAM,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IAC9D,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { EntityManager, Like } from 'typeorm'\n\nimport { Domain, EnvVar } from '@things-factory/shell'\n\n/**\n * A connection's per-domain values live in EnvVars named after it — `Connection::<name>::<key>` (an account, a\n * secret). Renaming the connection carries them along: otherwise the connection, under its new name, finds no\n * account, and nothing on the screen says why.\n *\n * Only the names change; the values are not read or rewritten. A name the new one would take that is already\n * there is refused by name — one of the two would be lost.\n */\nexport class ConnectionEnvVarCollision extends Error {\n code = 'connection-env-var-collision'\n constructor(names: string[]) {\n super(`connection-env-var-collision: ${names.join(', ')} already exist — the renamed connection's values cannot take those names`)\n }\n}\n\nexport const connectionEnvVarPrefix = (name: string) => `Connection::${name}::`\n\nexport async function carryConnectionEnvVars(tx: EntityManager, domain: Domain, from: string, to: string): Promise<string[]> {\n if (!from || !to || from === to) return []\n const repository = tx.getRepository(EnvVar)\n const oldPrefix = connectionEnvVarPrefix(from)\n const newPrefix = connectionEnvVarPrefix(to)\n\n /* LIKE narrows; the exact prefix decides — a `_` or `%` in a name is a wildcard to LIKE */\n const rows = (await repository.find({ where: { domain: { id: domain.id }, name: Like(`Connection::%`) } })).filter(row =>\n row.name.startsWith(oldPrefix)\n )\n if (!rows.length) return []\n\n const wanted = rows.map(row => newPrefix + row.name.slice(oldPrefix.length))\n const taken = (await repository.find({ where: { domain: { id: domain.id }, name: Like(`Connection::%`) } }))\n .map(row => row.name)\n .filter(name => wanted.includes(name))\n if (taken.length) throw new ConnectionEnvVarCollision(taken)\n\n for (const [i, row] of rows.entries()) {\n await repository.update({ id: row.id }, { name: wanted[i] })\n }\n return wanted\n}\n"]}
@@ -10,6 +10,7 @@ const connection_1 = require("./connection");
10
10
  const connection_type_1 = require("./connection-type");
11
11
  const domain_inheritance_1 = require("../../utils/domain-inheritance");
12
12
  const connection_secrets_1 = require("./connection-secrets");
13
+ const connection_env_vars_1 = require("./connection-env-vars");
13
14
  /**
14
15
  * The params a write stores (ADR-0112): a secret the caller sends is refused, a secret the caller
15
16
  * leaves out is kept from the stored row.
@@ -57,6 +58,9 @@ let ConnectionMutation = class ConnectionMutation {
57
58
  if (!connection) {
58
59
  throw notInThisDomain(name);
59
60
  }
61
+ if (patch.name && patch.name !== connection.name) {
62
+ await (0, connection_env_vars_1.carryConnectionEnvVars)(tx, domain, connection.name, patch.name);
63
+ }
60
64
  return await repository.save({
61
65
  ...connection,
62
66
  ...patch,
@@ -92,6 +96,9 @@ let ConnectionMutation = class ConnectionMutation {
92
96
  if (!connection) {
93
97
  throw notInThisDomain(newRecord.name || newRecord.id);
94
98
  }
99
+ if (newRecord.name && newRecord.name !== connection.name) {
100
+ await (0, connection_env_vars_1.carryConnectionEnvVars)(tx, domain, connection.name, newRecord.name);
101
+ }
95
102
  const result = await connectionRepo.save({
96
103
  ...connection,
97
104
  ...newRecord,
@@ -1 +1 @@
1
- {"version":3,"file":"connection-mutation.js","sourceRoot":"","sources":["../../../server/service/connection/connection-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAqF;AACrF,qCAA4B;AAE5B,iDAA6E;AAE7E,wEAAmE;AACnE,6CAA2D;AAC3D,uDAAkE;AAClE,uEAA0E;AAC1E,6DAA8F;AAE9F;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,OAA4B,EAAE,MAAmB;IACtE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,MAAM,EAAE,IAAI,CAAA;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC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Content":["import { Arg, Ctx, Directive, Mutation, Resolver, UseMiddleware } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository, Refusal, SpeakRefusals } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionStatus } from './connection'\nimport { ConnectionPatch, NewConnection } from './connection-type'\nimport { getDomainIdsWithAncestors } from '../../utils/domain-inheritance'\nimport { keepStoredSecrets, refuseSecretParams, withoutSecretsOf } from './connection-secrets'\n\n/**\n * The params a write stores (ADR-0112): a secret the caller sends is refused, a secret the caller\n * leaves out is kept from the stored row.\n *\n * A write that changes the connector type keeps none of the old type's secrets. They were secrets\n * under the old type's spec; the new type may not declare them, and then reading would show them.\n * When the old type is not registered here nobody can say which were secret, so none of its params\n * are carried over.\n */\nfunction paramsToStore(written: Partial<Connection>, stored?: Connection) {\n const type = written.type ?? stored?.type\n const name = written.name ?? stored?.name\n const typeChanged = Boolean(stored && written.type && written.type !== stored.type)\n\n if (written.params === undefined) {\n return typeChanged ? { params: withoutSecretsOf(stored.type, stored.params) } : {}\n }\n\n refuseSecretParams(type, name, written.params)\n return { params: typeChanged ? written.params : keepStoredSecrets(type, written.params, stored?.params) }\n}\n\n/**\n * A write names an existing row only through this: the row of that id or name **in the request's\n * domain**. `save` writes by primary key, so an id from another domain left in the object would\n * overwrite that domain's row - the lookup alone does not stop it.\n */\nfunction notInThisDomain(connection: string) {\n return new Refusal(\n 'connection-not-in-domain',\n { connection },\n `There is no connection \"${connection}\" in this domain.`\n )\n}\n\n@Resolver(Connection)\n@UseMiddleware(SpeakRefusals)\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 ...paramsToStore(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 if (!connection) {\n throw notInThisDomain(name)\n }\n\n return await repository.save({\n ...connection,\n ...patch,\n ...paramsToStore(patch, connection),\n id: connection.id,\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 /* A new row: an id it carries would make `save` overwrite the row of that id, wherever it is. */\n const { id, ...newRecord } = _createRecords[i]\n\n const result = await connectionRepo.save({\n ...newRecord,\n ...paramsToStore(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, domain: { id: domain.id } })\n\n if (!connection) {\n throw notInThisDomain(newRecord.name || newRecord.id)\n }\n\n const result = await connectionRepo.save({\n ...connection,\n ...newRecord,\n ...paramsToStore(newRecord, connection),\n id: connection.id,\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\n // ancestor 도메인을 closest-first 로 순회하여 first hit 사용\n const domainIds = await getDomainIdsWithAncestors(domain)\n var connection: Connection | null = null\n for (const did of domainIds) {\n connection = await repository.findOne({\n where: { domain: { id: did }, name },\n relations: ['domain', 'edge']\n })\n if (connection) break\n }\n\n if (!connection) {\n throw new Error(`Connection with name '${name}' not found`)\n }\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n if (connection.domain.id !== domain.id) {\n connection.domain = domain\n await connection.connect()\n /* on-demand 연결인 경우에 connection을 저장하지 말아야 한다. */\n } else {\n await connection.connect()\n await repository.save(connection)\n }\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Terminates a live connection.' })\n async disconnectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext) {\n const { domain } = context.state\n\n var repository = getRepository(Connection)\n\n // ancestor 도메인을 closest-first 로 순회하여 first hit 사용\n const domainIds = await getDomainIdsWithAncestors(domain)\n var connection: Connection | null = null\n for (const did of domainIds) {\n connection = await repository.findOne({\n where: { domain: { id: did }, name },\n relations: ['domain', 'edge']\n })\n if (connection) break\n }\n\n if (!connection) {\n throw new Error(`Connection with name '${name}' not found`)\n }\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n if (connection.domain.id !== domain.id) {\n connection.domain = domain\n await connection.disconnect()\n\n /* on-demand 연결인 경우에 connection을 저장하지 말아야 한다. */\n } else {\n await connection.disconnect()\n await repository.save(connection)\n }\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n }\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, {\n description: 'Imports multiple connections. Can overwrite existing connections if IDs or names match.'\n })\n async importConnections(\n @Arg('connections', type => [ConnectionPatch]) connections: Connection[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { tx, domain, user } = context.state\n\n const repository = tx.getRepository(Connection)\n\n await Promise.all(\n connections.map(async (connection: Connection) => {\n const { id, name } = connection\n\n if (id) {\n const sameId = await repository.findOneBy({ id })\n\n if (sameId) {\n if (sameId.domainId != domain.id) {\n throw `Connection with id '${id}:${name}' is already taken by another domain`\n }\n\n const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })\n if (sameName && sameName.id != id) {\n throw `Connection with name '${name}' is already taken by another connection`\n }\n\n await repository.save({\n ...sameId,\n ...connection,\n ...paramsToStore(connection, sameId),\n domain,\n updater: user\n })\n\n return\n }\n }\n\n await repository.save({\n ...connection,\n ...paramsToStore(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,+CAAqF;AACrF,qCAA4B;AAE5B,iDAA6E;AAE7E,wEAAmE;AACnE,6CAA2D;AAC3D,uDAAkE;AAClE,uEAA0E;AAC1E,6DAA8F;AAC9F,+DAA8D;AAE9D;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,OAA4B,EAAE,MAAmB;IACtE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,MAAM,EAAE,IAAI,CAAA;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,MAAM,EAAE,IAAI,CAAA;IACzC,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,CAAA;IAEnF,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAA,qCAAgB,EAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACpF,CAAC;IAED,IAAA,uCAAkB,EAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;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leware } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository, Refusal, SpeakRefusals } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionStatus } from './connection'\nimport { ConnectionPatch, NewConnection } from './connection-type'\nimport { getDomainIdsWithAncestors } from '../../utils/domain-inheritance'\nimport { keepStoredSecrets, refuseSecretParams, withoutSecretsOf } from './connection-secrets'\nimport { carryConnectionEnvVars } from './connection-env-vars'\n\n/**\n * The params a write stores (ADR-0112): a secret the caller sends is refused, a secret the caller\n * leaves out is kept from the stored row.\n *\n * A write that changes the connector type keeps none of the old type's secrets. They were secrets\n * under the old type's spec; the new type may not declare them, and then reading would show them.\n * When the old type is not registered here nobody can say which were secret, so none of its params\n * are carried over.\n */\nfunction paramsToStore(written: Partial<Connection>, stored?: Connection) {\n const type = written.type ?? stored?.type\n const name = written.name ?? stored?.name\n const typeChanged = Boolean(stored && written.type && written.type !== stored.type)\n\n if (written.params === undefined) {\n return typeChanged ? { params: withoutSecretsOf(stored.type, stored.params) } : {}\n }\n\n refuseSecretParams(type, name, written.params)\n return { params: typeChanged ? written.params : keepStoredSecrets(type, written.params, stored?.params) }\n}\n\n/**\n * A write names an existing row only through this: the row of that id or name **in the request's\n * domain**. `save` writes by primary key, so an id from another domain left in the object would\n * overwrite that domain's row - the lookup alone does not stop it.\n */\nfunction notInThisDomain(connection: string) {\n return new Refusal(\n 'connection-not-in-domain',\n { connection },\n `There is no connection \"${connection}\" in this domain.`\n )\n}\n\n@Resolver(Connection)\n@UseMiddleware(SpeakRefusals)\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 ...paramsToStore(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 if (!connection) {\n throw notInThisDomain(name)\n }\n\n if (patch.name && patch.name !== connection.name) {\n await carryConnectionEnvVars(tx, domain, connection.name, patch.name)\n }\n\n return await repository.save({\n ...connection,\n ...patch,\n ...paramsToStore(patch, connection),\n id: connection.id,\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 /* A new row: an id it carries would make `save` overwrite the row of that id, wherever it is. */\n const { id, ...newRecord } = _createRecords[i]\n\n const result = await connectionRepo.save({\n ...newRecord,\n ...paramsToStore(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, domain: { id: domain.id } })\n\n if (!connection) {\n throw notInThisDomain(newRecord.name || newRecord.id)\n }\n\n if (newRecord.name && newRecord.name !== connection.name) {\n await carryConnectionEnvVars(tx, domain, connection.name, newRecord.name)\n }\n\n const result = await connectionRepo.save({\n ...connection,\n ...newRecord,\n ...paramsToStore(newRecord, connection),\n id: connection.id,\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\n // ancestor 도메인을 closest-first 로 순회하여 first hit 사용\n const domainIds = await getDomainIdsWithAncestors(domain)\n var connection: Connection | null = null\n for (const did of domainIds) {\n connection = await repository.findOne({\n where: { domain: { id: did }, name },\n relations: ['domain', 'edge']\n })\n if (connection) break\n }\n\n if (!connection) {\n throw new Error(`Connection with name '${name}' not found`)\n }\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n if (connection.domain.id !== domain.id) {\n connection.domain = domain\n await connection.connect()\n /* on-demand 연결인 경우에 connection을 저장하지 말아야 한다. */\n } else {\n await connection.connect()\n await repository.save(connection)\n }\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'Terminates a live connection.' })\n async disconnectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext) {\n const { domain } = context.state\n\n var repository = getRepository(Connection)\n\n // ancestor 도메인을 closest-first 로 순회하여 first hit 사용\n const domainIds = await getDomainIdsWithAncestors(domain)\n var connection: Connection | null = null\n for (const did of domainIds) {\n connection = await repository.findOne({\n where: { domain: { id: did }, name },\n relations: ['domain', 'edge']\n })\n if (connection) break\n }\n\n if (!connection) {\n throw new Error(`Connection with name '${name}' not found`)\n }\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n\n /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */\n if (connection.domain.id !== domain.id) {\n connection.domain = domain\n await connection.disconnect()\n\n /* on-demand 연결인 경우에 connection을 저장하지 말아야 한다. */\n } else {\n await connection.disconnect()\n await repository.save(connection)\n }\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n }\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, {\n description: 'Imports multiple connections. Can overwrite existing connections if IDs or names match.'\n })\n async importConnections(\n @Arg('connections', type => [ConnectionPatch]) connections: Connection[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { tx, domain, user } = context.state\n\n const repository = tx.getRepository(Connection)\n\n await Promise.all(\n connections.map(async (connection: Connection) => {\n const { id, name } = connection\n\n if (id) {\n const sameId = await repository.findOneBy({ id })\n\n if (sameId) {\n if (sameId.domainId != domain.id) {\n throw `Connection with id '${id}:${name}' is already taken by another domain`\n }\n\n const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })\n if (sameName && sameName.id != id) {\n throw `Connection with name '${name}' is already taken by another connection`\n }\n\n await repository.save({\n ...sameId,\n ...connection,\n ...paramsToStore(connection, sameId),\n domain,\n updater: user\n })\n\n return\n }\n }\n\n await repository.save({\n ...connection,\n ...paramsToStore(connection),\n domain,\n updater: user,\n creator: user\n })\n })\n )\n\n return true\n }\n}\n"]}