Skip to content

Commit d8e23e4

Browse files
Use parser's API support for BigInt
- Use parser's API support instead of normalizing bigint/number ourself. Signed-off-by: Quoc-Hao Tran <[email protected]>
1 parent 4d094b0 commit d8e23e4

16 files changed

+151
-389
lines changed

tsp-typescript-client/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
},
1212
"devDependencies": {
1313
"@types/jest": "^27.0.1",
14-
"@types/json-bigint": "^1.0.1",
1514
"@types/node": "^11.13.8",
1615
"@types/node-fetch": "^2.3.3",
1716
"jest": "^27.1.0",
@@ -22,9 +21,9 @@
2221
"typescript": "latest"
2322
},
2423
"dependencies": {
25-
"json-bigint": "sidorares/json-bigint#2c0a5f896d7888e68e5f4ae3c7ea5cd42fd54473",
2624
"node-fetch": "^2.5.0",
27-
"rimraf": "latest"
25+
"rimraf": "latest",
26+
"when-json-met-bigint": "^0.21.0"
2827
},
2928
"scripts": {
3029
"prepare": "yarn run clean && yarn run build",

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { array, assertNumber, createNormalizer, record } from '../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { assertNumber, bigint } from '../protocol/serialization';
23
import { OutputElementStyle } from './styles';
34

45
export enum Type {
@@ -10,12 +11,15 @@ export interface AnnotationCategoriesModel {
1011
annotationCategories: string[];
1112
}
1213

13-
export const Annotation = createNormalizer<Annotation>({
14-
duration: BigInt,
15-
entryId: assertNumber,
16-
time: BigInt,
17-
style: OutputElementStyle,
18-
});
14+
export const AnnotationSchema: Schema = {
15+
annotations: {
16+
[Symbol.for(`any`)]: [{
17+
duration: bigint,
18+
entryId: assertNumber,
19+
time: bigint,
20+
}]
21+
}
22+
};
1923

2024
/**
2125
* Model for annotation
@@ -53,10 +57,6 @@ export interface Annotation {
5357
style?: OutputElementStyle;
5458
}
5559

56-
export const AnnotationModel = createNormalizer<AnnotationModel>({
57-
annotations: record(array(Annotation)),
58-
});
59-
6060
export interface AnnotationModel {
6161
annotations: { [category: string]: Annotation[] };
6262
}

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { createNormalizer } from '../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { bigint } from '../protocol/serialization';
23

3-
export const Bookmark = createNormalizer<Bookmark>({
4-
endTime: BigInt,
5-
startTime: BigInt,
6-
});
4+
export const BookmarkSchema: Schema = {
5+
endTime: bigint,
6+
startTime: bigint,
7+
};
78

89
/**
910
* Model for bookmark

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

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { array, assertNumber, createNormalizer, Normalizer } from '../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { assertNumber } from '../protocol/serialization';
23
import { OutputElementStyle } from './styles';
34

4-
export const Entry = createNormalizer<Entry>({
5+
export const EntrySchema: Schema = {
56
id: assertNumber,
67
parentId: assertNumber,
7-
style: {
8-
values: undefined,
9-
},
10-
});
8+
};
119

1210
/**
1311
* Basic entry interface
@@ -54,11 +52,7 @@ export interface EntryHeader {
5452
tooltip: string
5553
}
5654

57-
export function EntryModel<T extends Entry>(normalizer: Normalizer<T>): Normalizer<EntryModel<T>> {
58-
return createNormalizer<EntryModel<any>>({
59-
entries: array(normalizer),
60-
});
61-
}
55+
export const EntryModelSchema = (schema: Schema): Schema => ({ entries: [schema] });
6256

6357
/**
6458
* Entry model that will be returned by the server

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
2-
import { Trace } from './trace';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { assertNumber, bigint } from '../protocol/serialization';
3+
import { TraceSchema, Trace } from './trace';
34

4-
export const Experiment = createNormalizer<Experiment>({
5-
end: BigInt,
5+
export const ExperimentSchema: Schema = {
6+
end: bigint,
67
nbEvents: assertNumber,
7-
start: BigInt,
8-
traces: array(Trace),
9-
});
8+
start: bigint,
9+
traces: [TraceSchema],
10+
};
1011

1112
/**
1213
* Model of an experiment that contain one or more traces

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { createNormalizer } from '../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { bigint } from '../protocol/serialization';
23

3-
export const OutputDescriptor = createNormalizer<OutputDescriptor>({
4-
end: BigInt,
5-
queryParameters: undefined,
6-
start: BigInt,
7-
});
4+
export const OutputDescriptorSchema: Schema = {
5+
end: bigint,
6+
start: bigint,
7+
};
88

99
/**
1010
* Descriptor of a specific output provider

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Deserialized, createNormalizer, Normalizer } from '../../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
22

33
/**
44
* Response status
@@ -24,13 +24,7 @@ export enum ResponseStatus {
2424
CANCELLED = 'CANCELLED'
2525
}
2626

27-
export function GenericResponse<T>(): Normalizer<GenericResponse<Deserialized<T>>>;
28-
export function GenericResponse<T>(normalizer: Normalizer<T>): Normalizer<GenericResponse<T>>;
29-
export function GenericResponse<T>(normalizer?: Normalizer<T>): Normalizer<GenericResponse<T>> | Normalizer<GenericResponse<Deserialized<T>>> {
30-
return createNormalizer<GenericResponse<any>>({
31-
model: normalizer,
32-
});
33-
}
27+
export const GenericResponseSchema = (schema: Schema): Schema => ({ model: schema });
3428

3529
/**
3630
* Generic response that contains a model

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

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import { createNormalizer } from '../protocol/serialization';
2-
3-
export const OutputElementStyle = createNormalizer<OutputElementStyle>({
4-
values: undefined,
5-
});
6-
71
/**
82
* Output element style object for one style key. It supports style
93
* inheritance. To avoid creating new styles the element style can have a parent

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

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { assertNumber } from '../protocol/serialization';
23

3-
export const ColumnHeaderEntry = createNormalizer<ColumnHeaderEntry>({
4+
export const ColumnHeaderEntrySchema: Schema = {
45
id: assertNumber,
5-
});
6+
};
67

78
/**
89
* Column header
@@ -29,9 +30,9 @@ export interface ColumnHeaderEntry {
2930
type: string;
3031
}
3132

32-
export const Cell = createNormalizer<Cell>({
33+
export const CellSchema: Schema = {
3334
tags: assertNumber,
34-
});
35+
};
3536

3637
/**
3738
* Cell inside a table line
@@ -48,11 +49,11 @@ export interface Cell {
4849
tags?: number;
4950
}
5051

51-
export const Line = createNormalizer<Line>({
52-
cells: array(Cell),
52+
export const LineSchema = {
53+
cells: [CellSchema],
5354
index: assertNumber,
5455
tags: assertNumber,
55-
});
56+
};
5657

5758
/**
5859
* Line of a table
@@ -74,12 +75,12 @@ export interface Line {
7475
tags?: number;
7576
}
7677

77-
export const TableModel = createNormalizer<TableModel>({
78-
columnIds: array(assertNumber),
79-
lines: array(Line),
78+
export const TableModelSchema = {
79+
columnIds: [assertNumber],
80+
lines: [LineSchema],
8081
lowIndex: assertNumber,
8182
size: assertNumber,
82-
});
83+
};
8384

8485
/**
8586
* Model of a table

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

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { assertNumber, bigint } from '../protocol/serialization';
23
import { Entry } from './entry';
34
import { OutputElementStyle } from './styles';
45

5-
export const TimeGraphEntry = createNormalizer<TimeGraphEntry>({
6-
end: BigInt,
6+
export const TimeGraphEntrySchema: Schema = {
7+
end: bigint,
78
id: assertNumber,
89
parentId: assertNumber,
9-
start: BigInt,
10-
style: OutputElementStyle,
11-
});
10+
start: bigint,
11+
};
1212

1313
/**
1414
* Entry in a time graph
@@ -25,12 +25,11 @@ export interface TimeGraphEntry extends Entry {
2525
end: bigint;
2626
}
2727

28-
const TimeGraphState = createNormalizer<TimeGraphState>({
29-
end: BigInt,
30-
start: BigInt,
28+
const TimeGraphStateSchema: Schema = {
29+
end: bigint,
30+
start: bigint,
3131
tags: assertNumber,
32-
style: OutputElementStyle,
33-
});
32+
};
3433

3534
/**
3635
* Time graph state
@@ -62,10 +61,10 @@ export interface TimeGraphState {
6261
style?: OutputElementStyle;
6362
}
6463

65-
export const TimeGraphRow = createNormalizer<TimeGraphRow>({
64+
export const TimeGraphRowSchema: Schema = {
6665
entryId: assertNumber,
67-
states: array(TimeGraphState),
68-
});
66+
states: [TimeGraphStateSchema],
67+
};
6968

7069
/**
7170
* Time graph row described by an array of states for a specific entry
@@ -82,9 +81,9 @@ export interface TimeGraphRow {
8281
states: TimeGraphState[];
8382
}
8483

85-
export const TimeGraphModel = createNormalizer<TimeGraphModel>({
86-
rows: array(TimeGraphRow),
87-
});
84+
export const TimeGraphModelSchema: Schema = {
85+
rows: [TimeGraphRowSchema],
86+
};
8887

8988
/**
9089
* Time Graph model that will be returned by the server
@@ -93,13 +92,12 @@ export interface TimeGraphModel {
9392
rows: TimeGraphRow[];
9493
}
9594

96-
export const TimeGraphArrow = createNormalizer<TimeGraphArrow>({
97-
end: BigInt,
95+
export const TimeGraphArrowSchema: Schema = {
96+
end: bigint,
9897
sourceId: assertNumber,
99-
start: BigInt,
98+
start: bigint,
10099
targetId: assertNumber,
101-
style: OutputElementStyle,
102-
});
100+
};
103101

104102
/**
105103
* Arrow for time graph

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { assertNumber, createNormalizer } from '../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { assertNumber, bigint } from '../protocol/serialization';
23

3-
export const Trace = createNormalizer<Trace>({
4-
end: BigInt,
4+
export const TraceSchema: Schema = {
5+
end: bigint,
56
nbEvents: assertNumber,
6-
start: BigInt,
7-
});
7+
start: bigint,
8+
};
89

910
/**
1011
* Model of a single trace

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
1+
import { Schema } from 'when-json-met-bigint';
2+
import { assertNumber, number } from '../protocol/serialization';
23

3-
export const XYSeries = createNormalizer<XYSeries>({
4+
export const XYSeriesSchema: Schema = {
45
seriesId: assertNumber,
5-
xValues: array(Number), // lossy conversion if too big
6-
yValues: array(assertNumber),
7-
tags: array(assertNumber),
8-
});
6+
xValues: [number], // lossy conversion if too big
7+
yValues: [assertNumber],
8+
tags: [assertNumber],
9+
};
910

1011
/**
1112
* Represent a XY series and its values
@@ -47,9 +48,9 @@ export interface XYSeries {
4748
tags?: number[];
4849
}
4950

50-
export const XYModel = createNormalizer<XYModel>({
51-
series: array(XYSeries),
52-
});
51+
export const XYModelSchema: Schema = {
52+
series: [XYSeriesSchema],
53+
};
5354

5455
/**
5556
* Model of a XY chart, contains at least one XY series

0 commit comments

Comments
 (0)