Skip to content

Commit

Permalink
feat: values aggregates for events
Browse files Browse the repository at this point in the history
  • Loading branch information
BugGambit committed Jun 22, 2020
1 parent 2e6a4e2 commit 3184f7a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/__tests__/resources/events.integration.spec.ts
Expand Up @@ -95,6 +95,19 @@ describe('Events integration test', () => {
expect(aggregates[0].count).toBeDefined();
});

test('values aggregate', async () => {
const aggregates = await client.events.aggregate({
filter: {
source: 'WORKMATE',
},
fields: ['type'],
aggregate: 'values',
});
expect(aggregates.length).toBe(1);
expect(aggregates[0].count).toBeDefined();
expect(aggregates[0].value).toBeDefined();
});

test('delete', async () => {
await client.events.delete(createdEvents.map(event => ({ id: event.id })));
});
Expand Down
30 changes: 24 additions & 6 deletions src/types/types.ts
Expand Up @@ -196,6 +196,11 @@ export interface AggregateResponse {
* Size of the aggregation group
*/
count: number;

/**
* A unique value from the requested field
*/
value?: string | number;
}

/**
Expand Down Expand Up @@ -585,8 +590,8 @@ export interface DatapointsDeleteRange {
}

export type DatapointsDeleteRequest =
| InternalId & DatapointsDeleteRange
| ExternalId & DatapointsDeleteRange;
| (InternalId & DatapointsDeleteRange)
| (ExternalId & DatapointsDeleteRange);

export interface DatapointsGetAggregateDatapoint extends DatapointsMetadata {
datapoints: GetAggregateDatapoint[];
Expand Down Expand Up @@ -713,15 +718,28 @@ export type DeleteAssetMapping3D = AssetMapping3DBase;
export type EXECUTE = 'EXECUTE';

/**
* Query schema for asset aggregate endpoint
* Query schema for event aggregate endpoint
*/
export interface EventAggregateQuery {
export type EventAggregateQuery = EventCountAggregate | EventAdvancedAggregate;

export interface EventCountAggregate {
/**
* Filter on events with strict matching.
*/
filter?: EventFilter;
}

export interface EventAdvancedAggregate extends EventCountAggregate {
/**
* The field name(s) to apply the aggregation on. Currently limited to one field.
*/
fields: ('type' | 'subtype' | 'dataSetId')[];
/**
* Type of aggregation to apply. values - Get unique values (upto max 1000) in the specified field ordered by frequency.
*/
aggregate: 'values';
}

export type EventChange = EventChangeById | EventChangeByExternalId;

export interface EventChangeByExternalId extends EventPatch, ExternalId {}
Expand Down Expand Up @@ -1148,8 +1166,8 @@ export interface ItemsWrapper<T> {
export type LIST = 'LIST';

export type LatestDataBeforeRequest =
| InternalId & LatestDataPropertyFilter
| ExternalId & LatestDataPropertyFilter;
| (InternalId & LatestDataPropertyFilter)
| (ExternalId & LatestDataPropertyFilter);

export interface LatestDataPropertyFilter {
/**
Expand Down

0 comments on commit 3184f7a

Please sign in to comment.