Skip to content

Commit 006d5e9

Browse files
committed
Small tweak to the tsp client and packaging
Signed-off-by: Simon Delisle <simon.delisle@ericsson.com>
1 parent 55940d3 commit 006d5e9

File tree

7 files changed

+113
-53
lines changed

7 files changed

+113
-53
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "0.0.0",
44
"description": "Trace Server Protocol client written in TypeScript",
55
"author": "Ericsson and others",
6+
"main": "lib/index.js",
7+
"typings": "lib/index.d.ts",
68
"publishConfig": {
79
"access": "public"
810
},
@@ -26,12 +28,16 @@
2628
],
2729
"devDependencies": {
2830
"@types/node": "^10.12.2",
31+
"@types/node-fetch": "^2.1.2",
2932
"ts-node": "^7.0.1",
3033
"tslint": "^5.11.0",
3134
"tslint-language-service": "^0.9.9",
3235
"typescript": "^3.1.6"
3336
},
3437
"dependencies": {
3538
"node-fetch": "^2.2.1"
39+
},
40+
"scripts": {
41+
"build": "tsc"
3642
}
3743
}

src/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/********************************************************************************
2+
* Copyright (C) 2018 Ericsson and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the Eclipse
10+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
11+
* with the GNU Classpath Exception which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
********************************************************************************/
16+
17+
export * from './models/query/query';
18+
export * from './models/query/selection-time-query';
19+
export * from './models/query/table-query';
20+
export * from './models/query/time-query';
21+
export * from './models/response/entry-response';
22+
export * from './models/response/responses';
23+
export * from './models/response/timegraph-response';
24+
export * from './models/response/xy-response';
25+
export * from './models/bookmark';
26+
export * from './models/entry';
27+
export * from './models/experiment';
28+
export * from './models/filter';
29+
export * from './models/output-descriptor';
30+
export * from './models/table';
31+
export * from './models/timegraph';
32+
export * from './models/trace';
33+
export * from './models/xy';
34+
export * from './protocol/tsp-client';
35+
export * from './protocol/rest-client';

src/models/query/selection-time-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { TimeQuery } from './time-query';
1818
export class SelectionTimeQuery extends TimeQuery {
1919
private items: number[];
2020

21-
constructor(start: number, end: number, n: number, items: number[]) {
22-
super(start, end, n);
21+
constructor(timeRequested: number[], items: number[]) {
22+
super(timeRequested);
2323
this.items = items;
2424
}
2525
}

src/models/query/time-query.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
export class TimeQuery {
1818
private timesRequested: number[];
1919

20-
constructor(start: number, end: number, nb: number) {
21-
this.timesRequested = this.splitRangeIntoEqualParts(start, end, nb);
20+
constructor(timeRequested: number[]) {
21+
this.timesRequested = timeRequested;
2222
}
2323

24-
private splitRangeIntoEqualParts(start: number, end: number, nb: number): number[] {
25-
let result: number[] = new Array(nb);
24+
// constructor(start: number, end: number, nb: number) {
25+
// this.timesRequested = this.splitRangeIntoEqualParts(start, end, nb);
26+
// }
27+
28+
public static splitRangeIntoEqualParts(start: number, end: number, nb: number): number[] {
29+
const result: number[] = new Array(nb);
2630
if (nb === 1) {
2731
if (start === end) {
2832
result[0] = start;

src/protocol/rest-client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ import fetch from 'node-fetch';
2222
*/
2323
export class RestClient {
2424
private static async performRequest(verb: string, url: string, body?: any) {
25+
const jsonBody: string = JSON.stringify(body);
2526
const response = await fetch(url, {
27+
headers: {
28+
'Accept': 'application/json',
29+
'Content-Type': 'application/json'
30+
},
2631
method: verb,
27-
body: body
32+
body: jsonBody
2833
});
2934

3035
if (!response.ok) {

src/protocol/tsp-client.ts

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { Trace } from '../models/trace';
2727
import { RestClient } from './rest-client';
2828
import { Experiment } from '../models/experiment';
2929
import { OutputDescriptor } from '../models/output-descriptor';
30-
import { URLSearchParams } from 'url';
30+
// import { URLSearchParams } from 'url';
3131

3232
/**
3333
* Trace Server Protocol client
@@ -48,7 +48,7 @@ export class TspClient {
4848
* @returns List of Trace
4949
*/
5050
public async fetchTraces(): Promise<Trace[]> {
51-
const url = '${this.baseUrl}/traces';
51+
const url = this.baseUrl + '/traces';
5252
return await RestClient.get(url) as Trace[];
5353
}
5454

@@ -58,7 +58,7 @@ export class TspClient {
5858
* @returns The opened trace
5959
*/
6060
public async openTrace(parameters: Query): Promise<Trace> {
61-
const url = '${this.baseUrl}/traces';
61+
const url = this.baseUrl + '/traces';
6262
return await RestClient.post(url, parameters) as Trace;
6363
}
6464

@@ -70,23 +70,24 @@ export class TspClient {
7070
* @returns The deleted trace
7171
*/
7272
public async deleteTrace(traceUUID: string, deleteTrace?: boolean, removeCache?: boolean): Promise<Trace> {
73-
const url = '${this.baseUrl}/traces/${traceUUID}';
74-
const deleteParameters: URLSearchParams = new URLSearchParams();
75-
if (deleteTrace !== undefined) {
76-
deleteParameters.set('deleteTrace', deleteTrace.toString());
77-
}
78-
if (removeCache !== undefined) {
79-
deleteParameters.set('removeCache', removeCache.toString());
80-
}
81-
return await RestClient.delete(url, deleteParameters.toString()) as Trace;
73+
const url = this.baseUrl + '/traces/' + traceUUID;
74+
// TODO: renable when we figure how to use URLSearchParams
75+
// const deleteParameters: URLSearchParams = new URLSearchParams();
76+
// if (deleteTrace !== undefined) {
77+
// deleteParameters.set('deleteTrace', deleteTrace.toString());
78+
// }
79+
// if (removeCache !== undefined) {
80+
// deleteParameters.set('removeCache', removeCache.toString());
81+
// }
82+
return await RestClient.delete(url /*, deleteParameters.toString()*/) as Trace;
8283
}
8384

8485
/**
8586
* Fetch all available experiments on the server
8687
* @returns List of Experiment
8788
*/
8889
public async fetchExperiments(): Promise<Experiment[]> {
89-
const url = '${this.baseUrl}/experiments';
90+
const url = this.baseUrl + '/experiments';
9091
return await RestClient.get(url) as Experiment[];
9192
}
9293

@@ -96,7 +97,7 @@ export class TspClient {
9697
* @returns The experiment
9798
*/
9899
public async fetchExperiment(expUUID: string): Promise<Experiment> {
99-
const url = '${this.baseUrl}/experiments/${expUUID}';
100+
const url = this.baseUrl + '/experiments/' + expUUID;
100101
return await RestClient.get(url) as Experiment;
101102
}
102103

@@ -106,7 +107,7 @@ export class TspClient {
106107
* @returns The created experiment
107108
*/
108109
public async createExperiment(parameters: Query): Promise<Experiment> {
109-
const url = '${this.baseUrl}/experiments';
110+
const url = this.baseUrl + '/experiments';
110111
return await RestClient.post(url, parameters) as Experiment;
111112
}
112113

@@ -117,7 +118,7 @@ export class TspClient {
117118
* @returns The updated experiment
118119
*/
119120
public async updateExperiment(expUUID: string, parameters: Query): Promise<Experiment> {
120-
const url = '${this.baseUrl}/experiments/${expUUID}';
121+
const url = this.baseUrl + '/experiments/' + expUUID;
121122
return await RestClient.put(url, parameters) as Experiment;
122123
}
123124

@@ -127,7 +128,7 @@ export class TspClient {
127128
* @returns The deleted experiment
128129
*/
129130
public async deleteExperiment(expUUID: string): Promise<Experiment> {
130-
const url = '${this.baseUrl}/experiments/${expUUID}';
131+
const url = this.baseUrl + '/experiments/' + expUUID;
131132
return await RestClient.delete(url) as Experiment;
132133
}
133134

@@ -137,7 +138,7 @@ export class TspClient {
137138
* @returns List of OutputDescriptor
138139
*/
139140
public async experimentOutputs(expUUID: string): Promise<OutputDescriptor[]> {
140-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs';
141+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs';
141142
return await RestClient.get(url) as OutputDescriptor[];
142143
}
143144

@@ -149,7 +150,7 @@ export class TspClient {
149150
* @returns Generic entry response with entries of type T
150151
*/
151152
public async fetchXYTree<T extends BasicEntry, U extends EntryHeader>(expUUID: string, outputID: string, parameters: Query): Promise<XYEntryResponse<T, U>> {
152-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/XY/${outputID}/tree';
153+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/XY/' + outputID + '/tree';
153154
return await RestClient.post(url, parameters) as XYEntryResponse<T, U>;
154155
}
155156

@@ -161,7 +162,7 @@ export class TspClient {
161162
* @returns XY model response with the model of type T
162163
*/
163164
public async fetchXY<T extends XYModel>(expUUID: string, outputID: string, parameters: Query): Promise<XYModelResponse<T>> {
164-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/XY/${outputID}/xy';
165+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/XY/' + outputID + '/xy';
165166
return await RestClient.post(url, parameters) as XYModelResponse<T>;
166167
}
167168

@@ -175,16 +176,17 @@ export class TspClient {
175176
* @returns Map of key=name of the property and value=string value associated
176177
*/
177178
public async fetchXYToolTip(expUUID: string, outputID: string, xValue: number, yValue?: number, seriesID?: string): Promise<Map<string, string>> {
178-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/XY/${outputID}/tooltip';
179-
const xyTooltipParameters: URLSearchParams = new URLSearchParams();
180-
xyTooltipParameters.set('xValue', xValue.toString());
181-
if (yValue !== undefined) {
182-
xyTooltipParameters.set('yValue', yValue.toString());
183-
}
184-
if (seriesID !== undefined) {
185-
xyTooltipParameters.set('seriesID', seriesID);
186-
}
187-
return await RestClient.get(url, xyTooltipParameters.toString()) as Map<string, string>;
179+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/XY/' + outputID + '/tooltip';
180+
// TODO: renable when we figure how to use URLSearchParams
181+
// const xyTooltipParameters: URLSearchParams = new URLSearchParams();
182+
// xyTooltipParameters.set('xValue', xValue.toString());
183+
// if (yValue !== undefined) {
184+
// xyTooltipParameters.set('yValue', yValue.toString());
185+
// }
186+
// if (seriesID !== undefined) {
187+
// xyTooltipParameters.set('seriesID', seriesID);
188+
// }
189+
return await RestClient.get(url /*, xyTooltipParameters.toString()*/) as Map<string, string>;
188190
}
189191

190192
/**
@@ -195,7 +197,7 @@ export class TspClient {
195197
* @returns Time graph entry response with entries of type T and headers of type U
196198
*/
197199
public async fetchTimeGraphTree<T extends TimeGraphEntry, U extends EntryHeader>(expUUID: string, outputID: string, parameters: Query): Promise<TimeGraphEntryResponse<T, U>> {
198-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/timeGraph/${outputID}/tree';
200+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/timeGraph/' + outputID + '/tree';
199201
return await RestClient.post(url, parameters) as TimeGraphEntryResponse<T, U>;
200202
}
201203

@@ -207,7 +209,7 @@ export class TspClient {
207209
* @returns Generic response with the model of type T
208210
*/
209211
public async fetchTimeGraphStates<T extends TimeGraphRow>(expUUID: string, outputID: string, parameters: Query): Promise<GenericResponse<T>> {
210-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/timeGraph/${outputID}/states';
212+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/timeGraph/' + outputID + '/states';
211213
return await RestClient.post(url, parameters) as GenericResponse<T>;
212214
}
213215

@@ -219,7 +221,7 @@ export class TspClient {
219221
* @returns Generic response with the model of type T
220222
*/
221223
public async fetchTimeGraphArrows<T extends TimeGraphArrow>(expUUID: string, outputID: string, parameters: Query): Promise<GenericResponse<T>> {
222-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/timeGraph/${outputID}/arrows';
224+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/timeGraph/' + outputID + '/arrows';
223225
return await RestClient.post(url, parameters) as GenericResponse<T>;
224226
}
225227

@@ -233,16 +235,17 @@ export class TspClient {
233235
* @returns Map of key=name of the property and value=string value associated
234236
*/
235237
public async fetchTimeGraphToolTip(expUUID: string, outputID: string, time: number, entryID?: string, targetID?: string): Promise<Map<string, string>> {
236-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/timeGraph/${outputID}/tooltip';
237-
const statesTooltipParameters: URLSearchParams = new URLSearchParams();
238-
statesTooltipParameters.set('time', time.toString());
239-
if (entryID !== undefined) {
240-
statesTooltipParameters.set('entryID', entryID.toString());
241-
}
242-
if (targetID !== undefined) {
243-
statesTooltipParameters.set('targetID', targetID.toString());
244-
}
245-
return await RestClient.get(url, statesTooltipParameters.toString()) as Map<string, string>;
238+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/timeGraph/' + outputID + '/tooltip';
239+
// TODO: renable when we figure how to use URLSearchParams
240+
// const statesTooltipParameters: URLSearchParams = new URLSearchParams();
241+
// statesTooltipParameters.set('time', time.toString());
242+
// if (entryID !== undefined) {
243+
// statesTooltipParameters.set('entryID', entryID.toString());
244+
// }
245+
// if (targetID !== undefined) {
246+
// statesTooltipParameters.set('targetID', targetID.toString());
247+
// }
248+
return await RestClient.get(url /*, statesTooltipParameters.toString()*/) as Map<string, string>;
246249
}
247250

248251
/**
@@ -253,7 +256,7 @@ export class TspClient {
253256
* @returns Generic entry response with entries of type T
254257
*/
255258
public async fetchTableColumns<T extends ColumnHeaderEntry>(expUUID: string, outputID: string, parameters: Query): Promise<GenericEntryResponse<T>> {
256-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/table/${outputID}/columns';
259+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/table/' + outputID + '/columns';
257260
return await RestClient.post(url, parameters) as GenericEntryResponse<T>;
258261
}
259262

@@ -265,7 +268,7 @@ export class TspClient {
265268
* @returns Generic response with the model of type T
266269
*/
267270
public async fetchTableLines<T extends Table>(expUUID: string, outputID: string, parameters: Query): Promise<GenericResponse<T>> {
268-
const url = '${this.baseUrl}/experiments/${expUUID}/outputs/table/${outputID}/lines';
271+
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/table/' + outputID + '/lines';
269272
return await RestClient.post(url, parameters) as GenericResponse<T>;
270273
}
271274
}

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
# yarn lockfile v1
33

44

5-
"@types/node@^10.12.2":
5+
"@types/node-fetch@^2.1.2":
6+
version "2.1.2"
7+
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.1.2.tgz#8c5da14d70321e4c4ecd5db668e3f93cf6c7399f"
8+
integrity sha512-XroxUzLpKuL+CVkQqXlffRkEPi4Gh3Oui/mWyS7ztKiyqVxiU+h3imCW5I2NQmde5jK+3q++36/Q96cyRWsweg==
9+
dependencies:
10+
"@types/node" "*"
11+
12+
"@types/node@*", "@types/node@^10.12.2":
613
version "10.12.2"
714
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.2.tgz#d77f9faa027cadad9c912cd47f4f8b07b0fb0864"
815
integrity sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ==

0 commit comments

Comments
 (0)