Skip to content

Commit 9df9898

Browse files
haoadoreorangehaoadoresorange
authored and
haoadoresorange
committed
Add type to schemas
Signed-off-by: Quoc-Hao Tran <[email protected]>
1 parent d8e23e4 commit 9df9898

14 files changed

+25
-26
lines changed

tsp-typescript-client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dependencies": {
2424
"node-fetch": "^2.5.0",
2525
"rimraf": "latest",
26-
"when-json-met-bigint": "^0.21.0"
26+
"when-json-met-bigint": "^0.26.0"
2727
},
2828
"scripts": {
2929
"prepare": "yarn run clean && yarn run build",

tsp-typescript-client/src/models/annotation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface AnnotationCategoriesModel {
1111
annotationCategories: string[];
1212
}
1313

14-
export const AnnotationSchema: Schema = {
14+
export const AnnotationSchema: Schema<AnnotationModel> = {
1515
annotations: {
1616
[Symbol.for(`any`)]: [{
1717
duration: bigint,

tsp-typescript-client/src/models/bookmark.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Schema } from 'when-json-met-bigint';
22
import { bigint } from '../protocol/serialization';
33

4-
export const BookmarkSchema: Schema = {
4+
export const BookmarkSchema: Schema<Bookmark> = {
55
endTime: bigint,
66
startTime: bigint,
77
};

tsp-typescript-client/src/models/entry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Schema } from 'when-json-met-bigint';
22
import { assertNumber } from '../protocol/serialization';
33
import { OutputElementStyle } from './styles';
44

5-
export const EntrySchema: Schema = {
5+
export const EntrySchema: Schema<Entry> = {
66
id: assertNumber,
77
parentId: assertNumber,
88
};
@@ -52,7 +52,7 @@ export interface EntryHeader {
5252
tooltip: string
5353
}
5454

55-
export const EntryModelSchema = (schema: Schema): Schema => ({ entries: [schema] });
55+
export const EntryModelSchema = <T extends Entry>(schema: Schema<T>): Schema<EntryModel<T>> => ({ entries: [schema] });
5656

5757
/**
5858
* Entry model that will be returned by the server

tsp-typescript-client/src/models/experiment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Schema } from 'when-json-met-bigint';
22
import { assertNumber, bigint } from '../protocol/serialization';
33
import { TraceSchema, Trace } from './trace';
44

5-
export const ExperimentSchema: Schema = {
5+
export const ExperimentSchema: Schema<Experiment> = {
66
end: bigint,
77
nbEvents: assertNumber,
88
start: bigint,

tsp-typescript-client/src/models/output-descriptor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Schema } from 'when-json-met-bigint';
22
import { bigint } from '../protocol/serialization';
33

4-
export const OutputDescriptorSchema: Schema = {
4+
export const OutputDescriptorSchema: Schema<OutputDescriptor> = {
55
end: bigint,
66
start: bigint,
77
};

tsp-typescript-client/src/models/response/responses.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export enum ResponseStatus {
2424
CANCELLED = 'CANCELLED'
2525
}
2626

27-
export const GenericResponseSchema = (schema: Schema): Schema => ({ model: schema });
27+
export const GenericResponseSchema = <T>(schema: Schema<T>): Schema<GenericResponse<T>> => ({ model: schema });
2828

2929
/**
3030
* Generic response that contains a model

tsp-typescript-client/src/models/table.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Schema } from 'when-json-met-bigint';
22
import { assertNumber } from '../protocol/serialization';
33

4-
export const ColumnHeaderEntrySchema: Schema = {
4+
export const ColumnHeaderEntrySchema: Schema<ColumnHeaderEntry> = {
55
id: assertNumber,
66
};
77

@@ -30,7 +30,7 @@ export interface ColumnHeaderEntry {
3030
type: string;
3131
}
3232

33-
export const CellSchema: Schema = {
33+
export const CellSchema: Schema<Cell> = {
3434
tags: assertNumber,
3535
};
3636

@@ -49,7 +49,7 @@ export interface Cell {
4949
tags?: number;
5050
}
5151

52-
export const LineSchema = {
52+
export const LineSchema: Schema<Line> = {
5353
cells: [CellSchema],
5454
index: assertNumber,
5555
tags: assertNumber,
@@ -75,7 +75,7 @@ export interface Line {
7575
tags?: number;
7676
}
7777

78-
export const TableModelSchema = {
78+
export const TableModelSchema: Schema<TableModel> = {
7979
columnIds: [assertNumber],
8080
lines: [LineSchema],
8181
lowIndex: assertNumber,

tsp-typescript-client/src/models/timegraph.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { assertNumber, bigint } from '../protocol/serialization';
33
import { Entry } from './entry';
44
import { OutputElementStyle } from './styles';
55

6-
export const TimeGraphEntrySchema: Schema = {
6+
export const TimeGraphEntrySchema: Schema<TimeGraphEntry> = {
77
end: bigint,
88
id: assertNumber,
99
parentId: assertNumber,
@@ -25,7 +25,7 @@ export interface TimeGraphEntry extends Entry {
2525
end: bigint;
2626
}
2727

28-
const TimeGraphStateSchema: Schema = {
28+
const TimeGraphStateSchema: Schema<TimeGraphState> = {
2929
end: bigint,
3030
start: bigint,
3131
tags: assertNumber,
@@ -61,7 +61,7 @@ export interface TimeGraphState {
6161
style?: OutputElementStyle;
6262
}
6363

64-
export const TimeGraphRowSchema: Schema = {
64+
export const TimeGraphRowSchema: Schema<TimeGraphRow> = {
6565
entryId: assertNumber,
6666
states: [TimeGraphStateSchema],
6767
};
@@ -81,7 +81,7 @@ export interface TimeGraphRow {
8181
states: TimeGraphState[];
8282
}
8383

84-
export const TimeGraphModelSchema: Schema = {
84+
export const TimeGraphModelSchema: Schema<TimeGraphModel> = {
8585
rows: [TimeGraphRowSchema],
8686
};
8787

@@ -92,7 +92,7 @@ export interface TimeGraphModel {
9292
rows: TimeGraphRow[];
9393
}
9494

95-
export const TimeGraphArrowSchema: Schema = {
95+
export const TimeGraphArrowSchema: Schema<TimeGraphArrow> = {
9696
end: bigint,
9797
sourceId: assertNumber,
9898
start: bigint,

tsp-typescript-client/src/models/trace.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Schema } from 'when-json-met-bigint';
22
import { assertNumber, bigint } from '../protocol/serialization';
33

4-
export const TraceSchema: Schema = {
4+
export const TraceSchema: Schema<Trace> = {
55
end: bigint,
66
nbEvents: assertNumber,
77
start: bigint,

tsp-typescript-client/src/models/xy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Schema } from 'when-json-met-bigint';
22
import { assertNumber, number } from '../protocol/serialization';
33

4-
export const XYSeriesSchema: Schema = {
4+
export const XYSeriesSchema: Schema<XYSeries> = {
55
seriesId: assertNumber,
66
xValues: [number], // lossy conversion if too big
77
yValues: [assertNumber],
@@ -48,7 +48,7 @@ export interface XYSeries {
4848
tags?: number[];
4949
}
5050

51-
export const XYModelSchema: Schema = {
51+
export const XYModelSchema: Schema<XYModel> = {
5252
series: [XYSeriesSchema],
5353
};
5454

tsp-typescript-client/src/protocol/serialization.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const number = `number`;
55
/**
66
* Throw if `input` is not a `number`.
77
*/
8-
export const assertNumber: Schema = (num) => {
8+
export const assertNumber: Schema<number> = (num) => {
99
if (typeof num === bigint) {
1010
throw new TypeError(`Expected ${num} to be ${number}, found ${bigint}!`);
1111
}

tsp-typescript-client/src/protocol/tsp-client.ts

-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ export class TspClient {
164164
parameters: Query,
165165
): Promise<TspClientResponse<GenericResponse<XYModel>>> {
166166
const url = this.baseUrl + '/experiments/' + expUUID + '/outputs/XY/' + outputID + '/xy';
167-
console.log(JSON.stringify(GenericResponseSchema(XYModelSchema)));
168167
return RestClient.post(url, parameters, GenericResponseSchema(XYModelSchema));
169168
}
170169

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -6277,10 +6277,10 @@ whatwg-url@^8.0.0, whatwg-url@^8.4.0, whatwg-url@^8.5.0:
62776277
tr46 "^2.1.0"
62786278
webidl-conversions "^6.1.0"
62796279

6280-
when-json-met-bigint@^0.21.0:
6281-
version "0.21.0"
6282-
resolved "https://registry.yarnpkg.com/when-json-met-bigint/-/when-json-met-bigint-0.21.0.tgz#cf2d1e78690a84767b073d8c05f2a419df7117b7"
6283-
integrity sha512-RZwbeIBslSCWR7oXT03mV2ojwy5A+iO7k55mNsmqrsWnvUqJtmimv4M9wULd8I9jHZj7HnYlW1ZRaQzj2FRjFg==
6280+
when-json-met-bigint@^0.26.0:
6281+
version "0.26.0"
6282+
resolved "https://registry.yarnpkg.com/when-json-met-bigint/-/when-json-met-bigint-0.26.0.tgz#b456242735bd93f97fbbcd420f63b042e0ea6d1d"
6283+
integrity sha512-cTroBmOJ3cvnphEYL16fCXhjB4wN05ML9/BRaXuS5rBxOjOY7h1zhOi9c52NR7DsMtZArASKdFYMV9jePNiUFw==
62846284

62856285
which-boxed-primitive@^1.0.2:
62866286
version "1.0.2"

0 commit comments

Comments
 (0)