sdk icon indicating copy to clipboard operation
sdk copied to clipboard

`addEntity` should return the type of the added entity

Open aiwilliams opened this issue 3 years ago • 0 comments

In some integrations there is a type representing the entities created by the integration. Consider the following code:

function createGroupEntity(group: BitbucketGroup): BitbucketGroupEntity {
  return createIntegrationEntity({
    entityData: {
      source: group,
      assign: {
        displayName: group.name,
      },
    },
  }) as BitbucketGroupEntity;
}

export function createWorkspaceHasGroupRelationship(
  workspace: BitbucketWorkspaceEntity,
  group: BitbucketGroupEntity,
): BitbucketWorkspaceGroupRelationship {
  return {
    _key: `${workspace._key}|has|${group._key}`,
    _class: 'HAS',
    _type: BITBUCKET_WORKSPACE_GROUP_RELATIONSHIP_TYPE,
    _fromEntityKey: workspace._key,
    _toEntityKey: group._key,
    displayName: 'HAS',
  };
}

const workspaceEntity = ....;
const groupEntity = await jobState.addEntity(createGroupEntity(group)); // groupEntity is type Entity
createWorkspaceHasGroupRelationship(workspaceEntity, groupEntity); // < -- compilation problem

addEntity should return the type of the argument so that groupEntity: BitbucketGroupEntity.

Related to https://github.com/JupiterOne/sdk/issues/270

aiwilliams avatar Jun 30 '21 14:06 aiwilliams