diff --git a/src/__tests__/resources/events.integration.spec.ts b/src/__tests__/resources/events.integration.spec.ts index a006b99b76..408dfb7aca 100644 --- a/src/__tests__/resources/events.integration.spec.ts +++ b/src/__tests__/resources/events.integration.spec.ts @@ -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 }))); }); diff --git a/src/types/types.ts b/src/types/types.ts index 6e34d82be0..b2a821ed33 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -196,6 +196,11 @@ export interface AggregateResponse { * Size of the aggregation group */ count: number; + + /** + * A unique value from the requested field + */ + value?: string | number; } /** @@ -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[]; @@ -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 {} @@ -1148,8 +1166,8 @@ export interface ItemsWrapper { export type LIST = 'LIST'; export type LatestDataBeforeRequest = - | InternalId & LatestDataPropertyFilter - | ExternalId & LatestDataPropertyFilter; + | (InternalId & LatestDataPropertyFilter) + | (ExternalId & LatestDataPropertyFilter); export interface LatestDataPropertyFilter { /**