Skip to content

Commit

Permalink
Merge pull request #307 from JupiterOne/306-remove-getEntity
Browse files Browse the repository at this point in the history
Fixes #306 - Remove `jobState.getEntity` in favor of `jobState.findEn…
  • Loading branch information
austinkelleher authored Aug 24, 2020
2 parents 5601d13 + c159209 commit 92ef77c
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 104 deletions.
10 changes: 0 additions & 10 deletions docs/integrations/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,6 @@ Example usage:
const entity = await jobState.findEntity('myentitykey');
```

Similarly to `findEntity`, `getEntity` can also be used to look up an entity by
`_key`. `getEntity` will throw a `IntegrationMissingKeyError` error if the
entity does not exist.

Example usage:

```typescript
const entity = await jobState.getEntity('myentitykey');
```

More details about how the framework uses `jobState` is detailed in the [Data
collection](# Data collection) section below.

Expand Down
6 changes: 0 additions & 6 deletions packages/integration-sdk-core/src/types/jobState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ export interface JobState {
*/
addRelationships: (relationships: Relationship[]) => Promise<void>;

/**
* Gets an entity by _key
* Throws when !== 1 entity
*/
getEntity: (_key: string) => Promise<Entity>;

/**
* Finds an entity by `_key` and returns `null` if the entity does not exist.
* This function will also throw an error if multiple entities are found with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
import { v4 as uuid } from 'uuid';
import { FileSystemGraphObjectStore } from '../../storage';
import { vol } from 'memfs';
import {
Entity,
IntegrationMissingKeyError,
} from '@jupiterone/integration-sdk-core';
import { Entity } from '@jupiterone/integration-sdk-core';

jest.mock('fs');

Expand Down Expand Up @@ -88,37 +85,3 @@ describe('#findEntity', () => {
expect(await jobState.findEntity('invalid-entity-key')).toEqual(null);
});
});

describe('#getEntity', () => {
afterEach(() => {
vol.reset();
});

test('should get entity by _key', async () => {
const params = getMockCreateStepJobStateParams();
const jobState = createStepJobState(params);
const entity: Entity = {
_type: 'a_entity',
_class: 'A',
_key: 'a',
};

await jobState.addEntity(entity);
expect(await jobState.getEntity('a')).toStrictEqual(entity);
});

test('should throw if entity does not exist', async () => {
expect.assertions(2);
const params = getMockCreateStepJobStateParams();
const jobState = createStepJobState(params);

try {
await jobState.getEntity('invalid-entity-key');
} catch (err) {
expect(err instanceof IntegrationMissingKeyError).toEqual(true);
expect(err.message).toEqual(
`Failed to find entity in in-memory graph object metadata store (_key=invalid-entity-key)`,
);
}
});
});
18 changes: 0 additions & 18 deletions packages/integration-sdk-runtime/src/execution/jobState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Entity,
Relationship,
JobState,
IntegrationMissingKeyError,
} from '@jupiterone/integration-sdk-core';

import { FileSystemGraphObjectStore } from '../storage';
Expand Down Expand Up @@ -125,23 +124,6 @@ export function createStepJobState({
},
addRelationships,

getEntity: (_key: string) => {
const graphObjectMetadata = duplicateKeyTracker.getGraphObjectMetadata(
_key,
);

if (!graphObjectMetadata) {
throw new IntegrationMissingKeyError(
`Failed to find entity in in-memory graph object metadata store (_key=${_key})`,
);
}

return graphObjectStore.getEntity({
_key,
_type: graphObjectMetadata._type,
});
},

findEntity: async (_key: string) => {
const graphObjectMetadata = duplicateKeyTracker.getGraphObjectMetadata(
_key,
Expand Down
13 changes: 0 additions & 13 deletions packages/integration-sdk-testing/src/__tests__/jobState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ describe('entities', () => {
expect(jobState.collectedEntities).toEqual([]);
});

test('getEntity returns entity from jobState when _key matches', async () => {
const jobState = createMockJobState();
await jobState.addEntities(inputEntities);
const result = await jobState.getEntity('a');
expect(result).toEqual(inputEntities[0]);
});

test('getEntity throws Error when entity cannot be found in jobState', async () => {
const jobState = createMockJobState();
await jobState.addEntities(inputEntities);
await expect(jobState.getEntity('does-not-exist')).rejects.toThrow();
});

test('findEntity returns entity from jobState when _key matches', async () => {
const jobState = createMockJobState();
await jobState.addEntities(inputEntities);
Expand Down
19 changes: 0 additions & 19 deletions packages/integration-sdk-testing/src/jobState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,6 @@ export function createMockJobState({
},
addRelationships,

getEntity: async (_key: string) => {
const graphObjectMetadata = duplicateKeyTracker.getGraphObjectMetadata(
_key,
);

if (!graphObjectMetadata) {
throw new IntegrationMissingKeyError(
`Failed to find entity in in-memory graph object metadata store _key=${_key})`,
);
}

const entity = await getEntity({
_key,
_type: graphObjectMetadata._type,
});

return entity;
},

findEntity: async (_key: string) => {
const graphObjectMetadata = duplicateKeyTracker.getGraphObjectMetadata(
_key,
Expand Down
3 changes: 3 additions & 0 deletions packages/integration-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ createDirectRelationship({
- [#288](https://github.com/JupiterOne/sdk/issues/299) - Remove deprecated
`createIntegrationRelationship` function

- [#306](https://github.com/JupiterOne/sdk/issues/306) - Remove
`jobState.getEntity` in favor of `jobState.findEntity`

## 2.11.1 - 2020-08-21

### Fixed
Expand Down

0 comments on commit 92ef77c

Please sign in to comment.