Skip to content

Commit

Permalink
feat(alpha): multiple updates for simint APIs (#1174)
Browse files Browse the repository at this point in the history
- removed labels
- support for `includeAllFields` on routine revision list endpoint.
- removed redundant async as we lose the original type due to it (e.g. CursorAndAsyncIterator in some cases)
  • Loading branch information
polomani authored Nov 21, 2024
1 parent 2b80e4d commit 96bddf1
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 92 deletions.
1 change: 0 additions & 1 deletion packages/alpha/src/__tests__/api/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export const routineRevisionConfiguration: SimulatorRoutineRevisionConfiguration
schedule: { enabled: false },
dataSampling: {
enabled: true,
validationWindow: 0,
samplingWindow: 0,
granularity: 0,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 Cognite AS

import { describe, expect, test } from 'vitest';
import type CogniteClientAlpha from '../../cogniteClient';
import { setupLoggedInClient } from '../testUtils';
import {
fileExtensionTypes,
Expand Down Expand Up @@ -68,7 +69,6 @@ describeIf('simulator runs api', () => {
name: 'Test Simulator Model',
description: 'Test Simulator Model Desc',
dataSetId: 97552494921583,
labels: [{ externalId: 'air-quality-po-1' }],
type: 'WaterWell',
},
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 Cognite AS

import { describe, expect, test } from 'vitest';
import type CogniteClientAlpha from '../../cogniteClient';
import { setupLoggedInClient } from '../testUtils';
import {
fileExtensionTypes,
Expand Down
1 change: 1 addition & 0 deletions packages/alpha/src/__tests__/api/simulatorLogsApi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2023 Cognite AS
import { describe, expect, test } from 'vitest';
import type CogniteClientAlpha from '../../cogniteClient';
import { setupLoggedInClient } from '../testUtils';

const SHOULD_RUN_TESTS = process.env.RUN_SDK_SIMINT_TESTS === 'true';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 Cognite AS

import { describe, expect, test } from 'vitest';
import type CogniteClientAlpha from '../../cogniteClient';
import { setupLoggedInClient } from '../testUtils';
import {
fileExtensionTypes,
Expand Down Expand Up @@ -46,7 +47,6 @@ describeIf('simulator models api', () => {
name: 'Test Simulator Model',
description: 'Test Simulator Model Desc',
dataSetId: 97552494921583,
labels: [{ externalId: 'air-quality-po-1' }],
type: 'WaterWell',
},
]);
Expand Down
42 changes: 39 additions & 3 deletions packages/alpha/src/__tests__/api/simulatorRoutinesApi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2023 Cognite AS

import { describe, expect, test } from 'vitest';
import type CogniteClientAlpha from '../../cogniteClient';
import type { SimulatorRoutineRevision } from '../../types';
import { setupLoggedInClient } from '../testUtils';
import {
fileExtensionTypes,
Expand Down Expand Up @@ -68,7 +70,6 @@ describeIf('simulator routines api', () => {
name: 'Test Simulator Model',
description: 'Test Simulator Model Desc',
dataSetId: 97552494921583,
labels: [{ externalId: 'air-quality-po-1' }],
type: 'WaterWell',
},
]);
Expand Down Expand Up @@ -158,11 +159,46 @@ describeIf('simulator routines api', () => {
});

test('list routine revision', async () => {
const listResponse = await client.simulators.listRoutineRevisions();
const listResponse = await client.simulators.listRoutineRevisions({
sort: [
{
property: 'createdTime',
order: 'desc',
},
],
});
expect(listResponse.items.length).toBeGreaterThan(0);
const routineRevisionFound = listResponse.items.find(
const routineRevisionFound = listResponse.items.filter(
(item) => item.routineExternalId === routineExternalId
);
expect(routineRevisionFound.length).toBe(1);
expect(routineRevisionFound[0].externalId).toBe(
`${routineRevisionExternalId}_2`
);
});

test('list routine revision include all fields', async () => {
const listResponse = await client.simulators
.listRoutineRevisions<SimulatorRoutineRevision>({
filter: { allVersions: true },
includeAllFields: true,
sort: [
{
property: 'createdTime',
order: 'desc',
},
],
})
.autoPagingToArray();
expect(listResponse.length).toBeGreaterThan(0);
const routineRevisionFound = listResponse.find(
(item) => item.externalId === routineRevisionExternalId
);
expect(routineRevisionFound).toBeDefined();
expect(routineRevisionFound?.script).toEqual(routineRevisionScript);
expect(routineRevisionFound?.configuration).toEqual(
routineRevisionConfiguration
);
expect(routineRevisionFound?.externalId).toBe(routineRevisionExternalId);
});

Expand Down
2 changes: 2 additions & 0 deletions packages/alpha/src/__tests__/api/simulatorsApi.int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2023 Cognite AS

import { describe, expect, test } from 'vitest';
import type CogniteClientAlpha from '../../cogniteClient';
import type { SimulatorPatch } from '../../types';
import { setupLoggedInClient } from '../testUtils';
import {
fileExtensionTypes,
Expand Down
6 changes: 3 additions & 3 deletions packages/alpha/src/api/simulators/integrationsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import type {
} from '../../types';

export class IntegrationsAPI extends BaseResourceAPI<SimulatorIntegration> {
public create = async (items: SimulatorIntegrationCreate[]) => {
public create = (items: SimulatorIntegrationCreate[]) => {
return this.createEndpoint(items);
};

public list = async (filter?: SimulatorIntegrationFilterQuery) => {
public list = (filter?: SimulatorIntegrationFilterQuery) => {
return this.listEndpoint<SimulatorIntegrationFilterQuery>(
this.callListEndpointWithPost,
filter
);
};

public delete = async (ids: IdEither[]) => {
public delete = (ids: IdEither[]) => {
return this.deleteEndpoint(ids);
};
}
8 changes: 4 additions & 4 deletions packages/alpha/src/api/simulators/modelRevisionsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export class ModelRevisionsAPI extends BaseResourceAPI<SimulatorModelRevision> {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
}

public create = async (items: SimulatorModelRevisionCreate[]) => {
public create = (items: SimulatorModelRevisionCreate[]) => {
return this.createEndpoint(items);
};

public list = async (filter?: SimulatorModelRevisionFilterQuery) => {
public list = (filter?: SimulatorModelRevisionFilterQuery) => {
return this.listEndpoint<SimulatorModelRevisionFilterQuery>(
this.callListEndpointWithPost,
filter
Expand All @@ -31,11 +31,11 @@ export class ModelRevisionsAPI extends BaseResourceAPI<SimulatorModelRevision> {
return this.retrieveEndpoint(items);
}

public update = async (changes: SimulatorModelRevisionChange[]) => {
public update = (changes: SimulatorModelRevisionChange[]) => {
return this.updateEndpoint(changes);
};

public delete = async (ids: IdEither[]) => {
public delete = (ids: IdEither[]) => {
return this.deleteEndpoint(ids);
};
}
8 changes: 4 additions & 4 deletions packages/alpha/src/api/simulators/modelsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class ModelsAPI extends BaseResourceAPI<SimulatorModel> {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
}

public create = async (items: SimulatorModelCreate[]) => {
public create = (items: SimulatorModelCreate[]) => {
return this.createEndpoint(items);
};

public list = async (filter?: SimulatorModelFilterQuery) => {
public list = (filter?: SimulatorModelFilterQuery) => {
return this.listEndpoint<SimulatorModelFilterQuery>(
this.callListEndpointWithPost,
filter
Expand All @@ -36,11 +36,11 @@ export class ModelsAPI extends BaseResourceAPI<SimulatorModel> {
return this.retrieveEndpoint(items);
}

public update = async (changes: SimulatorModelChange[]) => {
public update = (changes: SimulatorModelChange[]) => {
return this.updateEndpoint(changes);
};

public delete = async (ids: IdEither[]) => {
public delete = (ids: IdEither[]) => {
return this.deleteEndpoint(ids);
};
}
13 changes: 4 additions & 9 deletions packages/alpha/src/api/simulators/routinesApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// Copyright 2024 Cognite AS

import {
BaseResourceAPI,
type CDFHttpClient,
type IdEither,
type MetadataMap,
} from '@cognite/sdk-core';
import { BaseResourceAPI, type IdEither } from '@cognite/sdk-core';
import type {
SimulatorRoutine,
SimulatorRoutineCreate,
Expand All @@ -20,18 +15,18 @@ export class RoutinesAPI extends BaseResourceAPI<SimulatorRoutine> {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
}

public create = async (items: SimulatorRoutineCreate[]) => {
public create = (items: SimulatorRoutineCreate[]) => {
return this.createEndpoint(items);
};

public list = async (filter?: SimulatorRoutineFilterQuery) => {
public list = (filter?: SimulatorRoutineFilterQuery) => {
return this.listEndpoint<SimulatorRoutineFilterQuery>(
this.callListEndpointWithPost,
filter
);
};

public delete = async (ids: IdEither[]) => {
public delete = (ids: IdEither[]) => {
return this.deleteEndpoint(ids);
};
}
37 changes: 30 additions & 7 deletions packages/alpha/src/api/simulators/routinesRevisionsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import { BaseResourceAPI, type IdEither } from '@cognite/sdk-core';
import type {
CursorResponse,
HttpResponse,
SimulatorRoutineRevision,
SimulatorRoutineRevisionBase,
SimulatorRoutineRevisionCreate,
SimulatorRoutineRevisionView,
SimulatorRoutineRevisionsFilterQuery,
} from '../../types';

Expand All @@ -12,25 +16,44 @@ export class RoutineRevisionsAPI extends BaseResourceAPI<SimulatorRoutineRevisio
* @hidden
*/
protected getDateProps() {
return this.pickDateProps(['items'], ['createdTime', 'lastUpdatedTime']);
return this.pickDateProps(['items'], ['createdTime']);
}

public create = async (items: SimulatorRoutineRevisionCreate[]) => {
public create = (items: SimulatorRoutineRevisionCreate[]) => {
return this.createEndpoint(items);
};

public list = async (filter?: SimulatorRoutineRevisionsFilterQuery) => {
return this.listEndpoint<SimulatorRoutineRevisionsFilterQuery>(
this.callListEndpointWithPost,
filter
private callRevisionListEndpoint = async <
RevisionResponseType extends SimulatorRoutineRevisionBase,
>(
query?: SimulatorRoutineRevisionsFilterQuery
): Promise<HttpResponse<CursorResponse<RevisionResponseType[]>>> => {
const response = await this.post<CursorResponse<RevisionResponseType[]>>(
this.listPostUrl,
{
data: query || {},
}
);
return response;
};

public list = <
RevisionResponseType extends
SimulatorRoutineRevisionBase = SimulatorRoutineRevisionView,
>(
query?: SimulatorRoutineRevisionsFilterQuery
) => {
return this.cursorBasedEndpoint<
SimulatorRoutineRevisionsFilterQuery,
RevisionResponseType
>(this.callRevisionListEndpoint, query);
};

public retrieve(items: IdEither[]) {
return this.retrieveEndpoint(items);
}

public delete = async (ids: IdEither[]) => {
public delete = (ids: IdEither[]) => {
return this.deleteEndpoint(ids);
};
}
2 changes: 1 addition & 1 deletion packages/alpha/src/api/simulators/simulationRunDataApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseResourceAPI } from '@cognite/sdk-core';
import type { SimulationRunData, SimulationRunId } from '../../types';

export class SimulationRunDataAPI extends BaseResourceAPI<SimulationRunData> {
public retrieve = async (ids: SimulationRunId[]) => {
public retrieve = (ids: SimulationRunId[]) => {
const path = this.url('list');

return this.retrieveEndpoint(ids, {}, path);
Expand Down
13 changes: 4 additions & 9 deletions packages/alpha/src/api/simulators/simulationRunsApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// Copyright 2023 Cognite AS

import {
BaseResourceAPI,
type CDFHttpClient,
type CogniteInternalId,
type MetadataMap,
} from '@cognite/sdk-core';
import { BaseResourceAPI, type CogniteInternalId } from '@cognite/sdk-core';
import type {
SimulationRun,
SimulationRunCreate,
Expand All @@ -23,19 +18,19 @@ export class SimulationRunsAPI extends BaseResourceAPI<SimulationRun> {
);
}

public run = async (items: SimulationRunCreate[]) => {
public run = (items: SimulationRunCreate[]) => {
const runUrl = this.url().slice(0, -2); // `/run` instead of `/runs`
return this.createEndpoint(items, runUrl);
};

public list = async (filter?: SimulationRunFilterQuery) => {
public list = (filter?: SimulationRunFilterQuery) => {
return this.listEndpoint<SimulationRunFilterQuery>(
this.callListEndpointWithPost,
filter
);
};

public retrieve = async (ids: CogniteInternalId[]) => {
public retrieve = (ids: CogniteInternalId[]) => {
const items = ids.map((id) => ({ id }));
return this.retrieveEndpoint(items);
};
Expand Down
Loading

0 comments on commit 96bddf1

Please sign in to comment.