-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipelines): add mlassociations resource to pipelines
feat(pipelines): add mlassociations resource to pipelines
- Loading branch information
1 parent
03c98af
commit 5ffde1a
Showing
12 changed files
with
297 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Resource from '../../Resource'; | ||
import Pipelines from '../Pipelines'; | ||
import { | ||
AssociatedPipelinesData, | ||
AssociationsListModel, | ||
CreateAssociation, | ||
EditAssociation, | ||
ListAssociationsParams, | ||
MLAssociationModel, | ||
} from './MLAssociationsInterfaces'; | ||
|
||
export default class MLAssociations extends Resource { | ||
static getBaseUrl = (pipelineId: string) => `/rest/search/v2/admin/pipelines/${pipelineId}/ml/model/associations`; | ||
|
||
list(pipelineId: string, options?: ListAssociationsParams) { | ||
return this.api.get<AssociationsListModel>(this.buildPath(MLAssociations.getBaseUrl(pipelineId), options)); | ||
} | ||
|
||
associate(pipelineId: string, options: CreateAssociation) { | ||
return this.api.post( | ||
this.buildPath(MLAssociations.getBaseUrl(pipelineId), {organizationId: this.api.organizationId}), | ||
options | ||
); | ||
} | ||
|
||
getAssociation(pipelineId: string, associationId: string) { | ||
return this.api.get<MLAssociationModel>( | ||
this.buildPath(`${MLAssociations.getBaseUrl(pipelineId)}/${associationId}`, { | ||
organizationId: this.api.organizationId, | ||
}) | ||
); | ||
} | ||
|
||
disassociate(pipelineId: string, modelId: string, associationId: string) { | ||
return this.api.delete( | ||
this.buildPath(`${MLAssociations.getBaseUrl(pipelineId)}/${associationId}/${modelId}`, { | ||
organizationId: this.api.organizationId, | ||
}) | ||
); | ||
} | ||
|
||
updateAssociation(pipelineId: string, associationId: string, options?: EditAssociation) { | ||
return this.api.put( | ||
this.buildPath(`${MLAssociations.getBaseUrl(pipelineId)}/${associationId}`, { | ||
organizationId: this.api.organizationId, | ||
}), | ||
options | ||
); | ||
} | ||
|
||
updatePosition(pipelineId: string, associationId: string, position: number) { | ||
return this.api.put( | ||
this.buildPath(`${MLAssociations.getBaseUrl(pipelineId)}/${associationId}/position`, { | ||
position, | ||
organizationId: this.api.organizationId, | ||
}), | ||
{} | ||
); | ||
} | ||
|
||
getAssociatedPipelines() { | ||
return this.api.get<AssociatedPipelinesData[]>( | ||
this.buildPath(`${Pipelines.baseUrl}/ml/model/associations`, {organizationId: this.api.organizationId}) | ||
); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/resources/Pipelines/MLAssociations/MLAssociationsInterfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
export interface AssociationsListModel { | ||
rules: MLAssociationModel[]; | ||
totalEntries: number; | ||
totalPages: number; | ||
} | ||
|
||
export interface MLAssociationModel { | ||
id: string; | ||
position: number; | ||
modelId: string; | ||
modelStatus: string; | ||
cacheMaximumAge: string; | ||
condition?: string; | ||
conditionDefinition?: string; | ||
customQueryParameters?: {}; | ||
enableWordCompletion?: boolean; | ||
exclusive?: boolean; | ||
intelligentTermDetection?: boolean; | ||
matchAdvancedExpression?: boolean; | ||
matchBasicExpression?: boolean; | ||
maxRecommendations?: number; | ||
modelDisplayName?: string; | ||
rankingModifier?: number; | ||
} | ||
|
||
export interface ListAssociationsParams { | ||
perPage?: number; | ||
page?: number; | ||
} | ||
|
||
export interface CreateAssociation extends EditAssociation { | ||
modelId: string; | ||
} | ||
|
||
export interface EditAssociation { | ||
cacheMaximumAge?: string; | ||
condition?: string; | ||
customQueryParameters?: {}; | ||
description?: string; | ||
enableWordCompletion?: boolean; | ||
exclusive?: boolean; | ||
intelligentTermDetection?: boolean; | ||
matchAdvancedExpression?: boolean; | ||
matchBasicExpression?: boolean; | ||
maxRecommendations?: number; | ||
rankingModifier?: number; | ||
} | ||
|
||
export interface AssociatedPipelinesData { | ||
modelId: string; | ||
associations: AssociatedPipelineModel[]; | ||
} | ||
|
||
export interface AssociatedPipelineModel { | ||
associationId: string; | ||
pipelineId: string; | ||
pipelineName: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './MLAssociations'; | ||
export * from './MLAssociationsInterfaces'; |
98 changes: 98 additions & 0 deletions
98
src/resources/Pipelines/MLAssociations/tests/MLAssociations.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import API from '../../../../APICore'; | ||
import Pipelines from '../../Pipelines'; | ||
import MLAssociations from '../MLAssociations'; | ||
|
||
jest.mock('../../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('MLAssociations', () => { | ||
let associations: MLAssociations; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
associations = new MLAssociations(api); | ||
}); | ||
|
||
describe('list', () => { | ||
it('should make a GET call to the specific MLAssociations url', () => { | ||
const pipelineId = 'diEnilEpip'; | ||
|
||
associations.list(pipelineId); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(MLAssociations.getBaseUrl(pipelineId)); | ||
}); | ||
}); | ||
|
||
describe('associate', () => { | ||
it('should make a POST call to the specific MLAssociations url', () => { | ||
const pipelineId = '-_-'; | ||
const options = {modelId: '0_0'}; | ||
|
||
associations.associate(pipelineId, options); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(`${MLAssociations.getBaseUrl(pipelineId)}`, options); | ||
}); | ||
}); | ||
|
||
describe('getAssociation', () => { | ||
it('should make a GET call to the specific MLAssociations url', () => { | ||
const pipelineId = '-W-'; | ||
const associationId = 'OWO'; | ||
|
||
associations.getAssociation(pipelineId, associationId); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${MLAssociations.getBaseUrl(pipelineId)}/${associationId}`); | ||
}); | ||
}); | ||
|
||
describe('disassociate', () => { | ||
it('should make a DELETE call to the specific MLAssociations url', () => { | ||
const pipelineId = '123'; | ||
const modelId = '321'; | ||
const associationId = '000'; | ||
|
||
associations.disassociate(pipelineId, modelId, associationId); | ||
expect(api.delete).toHaveBeenCalledTimes(1); | ||
expect(api.delete).toHaveBeenCalledWith( | ||
`${MLAssociations.getBaseUrl(pipelineId)}/${associationId}/${modelId}` | ||
); | ||
}); | ||
}); | ||
|
||
describe('updateAssociation', () => { | ||
it('should make a PUT call to the specific MLAssociations url', () => { | ||
const pipelineId = '999'; | ||
const associationId = '111'; | ||
const options = {exclusive: true}; | ||
|
||
associations.updateAssociation(pipelineId, associationId, options); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(`${MLAssociations.getBaseUrl(pipelineId)}/${associationId}`, options); | ||
}); | ||
}); | ||
|
||
describe('updatePosition', () => { | ||
it('should make a PUT call to the specific MLAssociations url', () => { | ||
const pipelineId = '222'; | ||
const associationId = '888'; | ||
const position = 6; | ||
|
||
associations.updatePosition(pipelineId, associationId, position); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith( | ||
`${MLAssociations.getBaseUrl(pipelineId)}/${associationId}/position?position=${position}`, | ||
{} | ||
); | ||
}); | ||
}); | ||
|
||
describe('getAssociatedPipelines', () => { | ||
it('should make a GET call to the specific MLAssociations url', () => { | ||
associations.getAssociatedPipelines(); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Pipelines.baseUrl}/ml/model/associations`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import API from '../../APICore'; | ||
import Resource from '../Resource'; | ||
import MLAssociations from './MLAssociations/MLAssociations'; | ||
import {PipelineBackendVersion} from './PipelinesInterfaces'; | ||
|
||
export default class Pipelines extends Resource { | ||
static baseUrl = '/rest/search/v2/admin/pipelines'; | ||
|
||
associations: MLAssociations; | ||
|
||
constructor(protected api: API) { | ||
super(api); | ||
|
||
this.associations = new MLAssociations(api); | ||
} | ||
|
||
getBackendVersion() { | ||
return this.api.get<PipelineBackendVersion>( | ||
this.buildPath(`${Pipelines.baseUrl}/ml/version`, {organizationId: this.api.organizationId}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface PipelineBackendVersion { | ||
version: '1' | '2'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './Pipelines'; | ||
export * from './PipelinesInterfaces'; | ||
export * from './MLAssociations/'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import API from '../../../APICore'; | ||
import Pipelines from '../Pipelines'; | ||
|
||
jest.mock('../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('Pipelines', () => { | ||
let pipelines: Pipelines; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
pipelines = new Pipelines(api); | ||
}); | ||
|
||
describe('getBackendVersion', () => { | ||
it('should make a GET call to the specific Pipelines url', () => { | ||
pipelines.getBackendVersion(); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Pipelines.baseUrl}/ml/version`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters