MCPcopy Create free account
hub / github.com/hashintel/hash / processEntityChange

Function processEntityChange

apps/hash-api/src/integrations/linear/sync-back.ts:38–153  ·  view source on GitHub ↗
({
  entity,
  graphApi,
  vaultClient,
}: {
  entity: HashEntity;
  graphApi: GraphApi;
  vaultClient: VaultClient;
})

Source from the content-addressed store, hash-verified

36];
37
38export const processEntityChange = async ({
39 entity,
40 graphApi,
41 vaultClient,
42}: {
43 entity: HashEntity;
44 graphApi: GraphApi;
45 vaultClient: VaultClient;
46}) => {
47 const { entityTypeIds } = entity.metadata;
48
49 if (
50 !entityTypeIds.some(
51 (entityTypeId) => !supportedLinearTypeIds.includes(entityTypeId),
52 )
53 ) {
54 throw new Error(
55 `Entity with entity type(s) ${entityTypeIds.join(", ")} passed to Linear sync back processor – supported types are ${supportedLinearEntityTypeIds.join(
56 ", ",
57 )}.`,
58 );
59 }
60
61 const linearMachineActorId = await getMachineIdByIdentifier(
62 { graphApi },
63 { actorId: systemAccountId },
64 { identifier: "linear" },
65 ).then((maybeMachineId) => {
66 if (!maybeMachineId) {
67 throw new Error("Failed to get linear bot");
68 }
69 return maybeMachineId;
70 });
71
72 if (entity.metadata.provenance.edition.createdById === linearMachineActorId) {
73 /**
74 * To prevent update loops where changes from linear are saved in HASH, and
75 * then propagate back to linear, only consider entity editions that weren't
76 * created by the Linear machine account's actorId.
77 */
78 return;
79 }
80
81 const graphContext: ImpureGraphContext = {
82 graphApi,
83 provenance: {
84 actorType: "machine",
85 origin: {
86 /**
87 * @todo use correct EntityId for Flow when Linear integration migrated to Flows
88 */
89 id: "linear-integration",
90 type: "flow",
91 },
92 },
93 };
94
95 const linearEntityToUpdate = entityTypeIds.some(

Callers

nothing calls this directly

Calls 10

getMachineIdByIdentifierFunction · 0.90
getLatestEntityByIdFunction · 0.90
createTemporalClientFunction · 0.90
extractWebIdFromEntityIdFunction · 0.90
entityIdFromComponentsFunction · 0.90
generateUuidFunction · 0.90
thenMethod · 0.80
toJSONMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected