Skip to content

Commit

Permalink
Align client classes with the TSP specification
Browse files Browse the repository at this point in the history
Fixes #3

The rest methods should not use generic types, as it would imply that
consumers of this client need to know about the details of each
potential sub-class, which is one thing we should avoid. Rather the
protocol should be self-descriptive to provide extra data in one
specific way.

Signed-off-by: Geneviève Bastien <[email protected]>
  • Loading branch information
tahini committed Sep 28, 2020
1 parent 1a3b29c commit c099112
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 69 deletions.
21 changes: 15 additions & 6 deletions src/models/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ export interface Entry {
id: number;

/**
* Parent entry Id, or -1 if the entry does not have a parent
* Array of string that represant the content of each column
*/
parentId: number;
labels: string[];

/**
* Array of string that represant the content of each column
* Parent entry Id. if unset, the entry does not have a parent
*/
labels: string[];
parentId?: number;

/**
* Indicate if the entry will have row data
*/
hasData?: boolean;

/**
* Style key used to search for a The style map can be obtained by using the style endpoint.
Expand All @@ -33,16 +38,20 @@ export interface EntryHeader {
* Displayed name
*/
name: string
/**
* The description of this header field
*/
tooltip: string
}

/**
* Entry model that will be returned by the server
*/
export interface EntryModel<T extends Entry, U extends EntryHeader> {
export interface EntryModel<T extends Entry> {
/**
* Array of entry header
*/
headers: U[];
headers: EntryHeader[];

/**
* Array of entry
Expand Down
2 changes: 1 addition & 1 deletion src/models/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface OutputElementStyle {
/**
* Style values to override or define properties
*/
styleValues: { [key: string]: any };
values: { [key: string]: any };
}

/**
Expand Down
38 changes: 9 additions & 29 deletions src/models/timegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,15 @@ import { OutputElementStyle } from './styles';
* Entry in a time graph
*/
export interface TimeGraphEntry extends Entry {
/**
* Type of the entry
*/
type: string;

/**
* Start time of the entry
*/
startTime: number;
start: number;

/**
* End time of the entry
*/
endTime: number;

/**
* Indicate if the entry will have row data
*/
hasRowModel: boolean;
end: number;
}

/**
Expand Down Expand Up @@ -55,27 +45,22 @@ export interface TimeGraphState {
/**
* Start time of the state
*/
startTime: number;
start: number;

/**
* End time of the state
*/
duration: number;
end: number;

/**
* Label to apply to the state
*/
label: string;

/**
* Values associated to the state
*/
value: number;
label?: string;

/**
* Tags for the state, used when the state pass a filter
*/
tags: number;
tags?: number;

/**
* Optional information on the style to format this state
Expand All @@ -95,22 +80,17 @@ export interface TimeGraphArrow {
/**
* Destination entry Id for the arrow
*/
destinationId: number;
targetId: number;

/**
* Start time of the arrow
*/
startTime: number;
start: number;

/**
* Duration of the arrow
*/
duration: number;

/**
* Value associated to the arrow
*/
value: number;
end: number;

/**
* Optional information on the style to format this arrow
Expand Down
19 changes: 12 additions & 7 deletions src/models/xy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface XYModel {
/**
* Array of XY series
*/
series: { [key: string]: XYSeries };
series: XYSeries[];
}

/**
Expand All @@ -25,22 +25,22 @@ export interface XYSeries {
/**
* Name of the series
*/
name: string;
seriesName: string;

/**
* Ìd of the series
*/
id: string;
seriesId: number;

/**
* Description of the X axis
*/
xAxis: Axis;
xAxis: XYAxis;

/**
* Description of the Y axis
*/
yAxis: Axis;
yAxis: XYAxis;

/**
* Series' X values
Expand All @@ -61,14 +61,19 @@ export interface XYSeries {
/**
* Description of an axis for XY chart
*/
export interface Axis {
export interface XYAxis {
/**
* Label of the axis
*/
label: string;

/**
* Type of units used for the axis
* The units used for the axis, to be appended to the numbers
*/
unit: string;

/**
* Type of data for this axis, to give hint on number formatting
*/
dataType: string;
}
52 changes: 26 additions & 26 deletions src/protocol/tsp-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Query } from '../models/query/query';
import { GenericResponse } from '../models/response/responses';
import { XYModel } from '../models/xy';
import { TimeGraphArrow, TimeGraphModel } from '../models/timegraph';
import { TableModel } from '../models/table';
import { TimeGraphEntry, TimeGraphArrow, TimeGraphModel } from '../models/timegraph';
import { TableModel, ColumnHeaderEntry } from '../models/table';
import { Trace } from '../models/trace';
import { RestClient } from './rest-client';
import { Experiment } from '../models/experiment';
Expand Down Expand Up @@ -137,24 +137,24 @@ export class TspClient {
* @param expUUID Experiment UUID
* @param outputID Output ID
* @param parameters Query object
* @returns Generic entry response with entries of type T
* @returns Generic entry response with entries
*/
public async fetchXYTree<M extends Entry, H extends EntryHeader>(expUUID: string,
outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<EntryModel<M, H>>>> {
public async fetchXYTree(expUUID: string,
outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<EntryModel<Entry>>>> {
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/XY/' + outputID + '/tree';
return await RestClient.post<GenericResponse<EntryModel<M, H>>>(url, parameters);
return await RestClient.post<GenericResponse<EntryModel<Entry>>>(url, parameters);
}

/**
* Fetch XY. model extends XYModel
* @param expUUID Experiment UUID
* @param outputID Output ID
* @param parameters Query object
* @returns XY model response with the model of type T
* @returns XY model response with the model
*/
public async fetchXY<T extends XYModel>(expUUID: string, outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<T>>> {
public async fetchXY(expUUID: string, outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<XYModel>>> {
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/XY/' + outputID + '/xy';
return await RestClient.post<GenericResponse<T>>(url, parameters);
return await RestClient.post<GenericResponse<XYModel>>(url, parameters);
}

/**
Expand Down Expand Up @@ -186,36 +186,36 @@ export class TspClient {
* @param expUUID Experiment UUID
* @param outputID Output ID
* @param parameters Query object
* @returns Time graph entry response with entries of type T and headers of type U
* @returns Time graph entry response with entries of type TimeGraphEntry
*/
public async fetchTimeGraphTree<M extends Entry, H extends EntryHeader>(expUUID: string,
outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<EntryModel<M, H>>>> {
public async fetchTimeGraphTree(expUUID: string,
outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<EntryModel<TimeGraphEntry>>>> {
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/timeGraph/' + outputID + '/tree';
return await RestClient.post<GenericResponse<EntryModel<M, H>>>(url, parameters);
return await RestClient.post<GenericResponse<EntryModel<TimeGraphEntry>>>(url, parameters);
}

/**
* Fetch Time Graph states. Model extends TimeGraphModel
* @param expUUID Experiment UUID
* @param outputID Output ID
* @param parameters Query object
* @returns Generic response with the model of type T
* @returns Generic response with the model
*/
public async fetchTimeGraphStates<T extends TimeGraphModel>(expUUID: string, outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<T>>> {
public async fetchTimeGraphStates(expUUID: string, outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<TimeGraphModel>>> {
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/timeGraph/' + outputID + '/states';
return await RestClient.post<GenericResponse<T>>(url, parameters);
return await RestClient.post<GenericResponse<TimeGraphModel>>(url, parameters);
}

/**
* Fetch Time Graph arrows. Model extends TimeGraphArrow
* @param expUUID Experiment UUID
* @param outputID Output ID
* @param parameters Query object
* @returns Generic response with the model of type T
* @returns Generic response with the model
*/
public async fetchTimeGraphArrows<T extends TimeGraphArrow>(expUUID: string, outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<T>>> {
public async fetchTimeGraphArrows(expUUID: string, outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<TimeGraphArrow>>> {
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/timeGraph/' + outputID + '/arrows';
return await RestClient.post<GenericResponse<T>>(url, parameters);
return await RestClient.post<GenericResponse<TimeGraphArrow>>(url, parameters);
}

/**
Expand Down Expand Up @@ -246,24 +246,24 @@ export class TspClient {
* @param expUUID Experiment UUID
* @param outputID Output ID
* @param parameters Query object
* @returns Generic entry response with entries of type T
* @returns Generic entry response with columns headers as model
*/
public async fetchTableColumns<M extends Entry, H extends EntryHeader>(expUUID: string,
outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<EntryModel<M, H>>>> {
public async fetchTableColumns(expUUID: string,
outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<ColumnHeaderEntry[]>>> {
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/table/' + outputID + '/columns';
return await RestClient.post<GenericResponse<EntryModel<M, H>>>(url, parameters);
return await RestClient.post<GenericResponse<ColumnHeaderEntry[]>>(url, parameters);
}

/**
* Fetch Table lines
* @param expUUID Experiment UUID
* @param outputID Output ID
* @param parameters Query object
* @returns Generic response with the model of type T
* @returns Generic response with the model
*/
public async fetchTableLines<T extends TableModel>(expUUID: string, outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<T>>> {
public async fetchTableLines(expUUID: string, outputID: string, parameters: Query): Promise<TspClientResponse<GenericResponse<TableModel>>> {
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/table/' + outputID + '/lines';
return await RestClient.post<GenericResponse<T>>(url, parameters);
return await RestClient.post<GenericResponse<TableModel>>(url, parameters);
}

/**
Expand Down

0 comments on commit c099112

Please sign in to comment.