Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parser's API support for BigInt #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions tsp-typescript-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/json-bigint": "^1.0.1",
"@types/node": "^11.13.8",
"@types/node-fetch": "^2.3.3",
"jest": "^27.1.0",
Expand All @@ -22,9 +21,9 @@
"typescript": "latest"
},
"dependencies": {
"json-bigint": "sidorares/json-bigint#2c0a5f896d7888e68e5f4ae3c7ea5cd42fd54473",
"node-fetch": "^2.5.0",
"rimraf": "latest"
"rimraf": "latest",
"when-json-met-bigint": "^0.27.0"
},
"scripts": {
"prepare": "yarn run clean && yarn run build",
Expand Down
22 changes: 11 additions & 11 deletions tsp-typescript-client/src/models/annotation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { array, assertNumber, createNormalizer, record } from '../protocol/serialization';
import { Schema } from 'when-json-met-bigint';
import { assertNumber, bigint } from '../protocol/serialization';
import { OutputElementStyle } from './styles';

export enum Type {
Expand All @@ -10,12 +11,15 @@ export interface AnnotationCategoriesModel {
annotationCategories: string[];
}

export const Annotation = createNormalizer<Annotation>({
duration: BigInt,
entryId: assertNumber,
time: BigInt,
style: OutputElementStyle,
});
export const AnnotationSchema: Schema<AnnotationModel> = {
annotations: {
[Symbol.for(`any`)]: [{
duration: bigint,
entryId: assertNumber,
time: bigint,
}]
}
};

/**
* Model for annotation
Expand Down Expand Up @@ -53,10 +57,6 @@ export interface Annotation {
style?: OutputElementStyle;
}

export const AnnotationModel = createNormalizer<AnnotationModel>({
annotations: record(array(Annotation)),
});

export interface AnnotationModel {
annotations: { [category: string]: Annotation[] };
}
11 changes: 6 additions & 5 deletions tsp-typescript-client/src/models/bookmark.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createNormalizer } from '../protocol/serialization';
import { Schema } from 'when-json-met-bigint';
import { bigint } from '../protocol/serialization';

export const Bookmark = createNormalizer<Bookmark>({
endTime: BigInt,
startTime: BigInt,
});
export const BookmarkSchema: Schema<Bookmark> = {
endTime: bigint,
startTime: bigint,
};

/**
* Model for bookmark
Expand Down
16 changes: 5 additions & 11 deletions tsp-typescript-client/src/models/entry.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { array, assertNumber, createNormalizer, Normalizer } from '../protocol/serialization';
import { Schema } from 'when-json-met-bigint';
import { assertNumber } from '../protocol/serialization';
import { OutputElementStyle } from './styles';

export const Entry = createNormalizer<Entry>({
export const EntrySchema: Schema<Entry> = {
id: assertNumber,
parentId: assertNumber,
style: {
values: undefined,
},
});
};

/**
* Basic entry interface
Expand Down Expand Up @@ -54,11 +52,7 @@ export interface EntryHeader {
tooltip: string
}

export function EntryModel<T extends Entry>(normalizer: Normalizer<T>): Normalizer<EntryModel<T>> {
return createNormalizer<EntryModel<any>>({
entries: array(normalizer),
});
}
export const EntryModelSchema = <T extends Entry>(schema: Schema<T>): Schema<EntryModel<T>> => ({ entries: [schema] });

/**
* Entry model that will be returned by the server
Expand Down
15 changes: 8 additions & 7 deletions tsp-typescript-client/src/models/experiment.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
import { Trace } from './trace';
import { Schema } from 'when-json-met-bigint';
import { assertNumber, bigint } from '../protocol/serialization';
import { TraceSchema, Trace } from './trace';

export const Experiment = createNormalizer<Experiment>({
end: BigInt,
export const ExperimentSchema: Schema<Experiment> = {
end: bigint,
nbEvents: assertNumber,
start: BigInt,
traces: array(Trace),
});
start: bigint,
traces: [TraceSchema],
};

/**
* Model of an experiment that contain one or more traces
Expand Down
12 changes: 6 additions & 6 deletions tsp-typescript-client/src/models/output-descriptor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createNormalizer } from '../protocol/serialization';
import { Schema } from 'when-json-met-bigint';
import { bigint } from '../protocol/serialization';

export const OutputDescriptor = createNormalizer<OutputDescriptor>({
end: BigInt,
queryParameters: undefined,
start: BigInt,
});
export const OutputDescriptorSchema: Schema<OutputDescriptor> = {
end: bigint,
start: bigint,
};

/**
* Descriptor of a specific output provider
Expand Down
10 changes: 2 additions & 8 deletions tsp-typescript-client/src/models/response/responses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Deserialized, createNormalizer, Normalizer } from '../../protocol/serialization';
import { Schema } from 'when-json-met-bigint';

/**
* Response status
Expand All @@ -24,13 +24,7 @@ export enum ResponseStatus {
CANCELLED = 'CANCELLED'
}

export function GenericResponse<T>(): Normalizer<GenericResponse<Deserialized<T>>>;
export function GenericResponse<T>(normalizer: Normalizer<T>): Normalizer<GenericResponse<T>>;
export function GenericResponse<T>(normalizer?: Normalizer<T>): Normalizer<GenericResponse<T>> | Normalizer<GenericResponse<Deserialized<T>>> {
return createNormalizer<GenericResponse<any>>({
model: normalizer,
});
}
export const GenericResponseSchema = <T>(schema: Schema<T>): Schema<GenericResponse<T>> => ({ model: schema });

/**
* Generic response that contains a model
Expand Down
6 changes: 0 additions & 6 deletions tsp-typescript-client/src/models/styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { createNormalizer } from '../protocol/serialization';

export const OutputElementStyle = createNormalizer<OutputElementStyle>({
values: undefined,
});

/**
* Output element style object for one style key. It supports style
* inheritance. To avoid creating new styles the element style can have a parent
Expand Down
25 changes: 13 additions & 12 deletions tsp-typescript-client/src/models/table.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
import { Schema } from 'when-json-met-bigint';
import { assertNumber } from '../protocol/serialization';

export const ColumnHeaderEntry = createNormalizer<ColumnHeaderEntry>({
export const ColumnHeaderEntrySchema: Schema<ColumnHeaderEntry> = {
id: assertNumber,
});
};

/**
* Column header
Expand All @@ -29,9 +30,9 @@ export interface ColumnHeaderEntry {
type: string;
}

export const Cell = createNormalizer<Cell>({
export const CellSchema: Schema<Cell> = {
tags: assertNumber,
});
};

/**
* Cell inside a table line
Expand All @@ -48,11 +49,11 @@ export interface Cell {
tags?: number;
}

export const Line = createNormalizer<Line>({
cells: array(Cell),
export const LineSchema: Schema<Line> = {
cells: [CellSchema],
index: assertNumber,
tags: assertNumber,
});
};

/**
* Line of a table
Expand All @@ -74,12 +75,12 @@ export interface Line {
tags?: number;
}

export const TableModel = createNormalizer<TableModel>({
columnIds: array(assertNumber),
lines: array(Line),
export const TableModelSchema: Schema<TableModel> = {
columnIds: [assertNumber],
lines: [LineSchema],
lowIndex: assertNumber,
size: assertNumber,
});
};

/**
* Model of a table
Expand Down
42 changes: 20 additions & 22 deletions tsp-typescript-client/src/models/timegraph.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
import { Schema } from 'when-json-met-bigint';
import { assertNumber, bigint } from '../protocol/serialization';
import { Entry } from './entry';
import { OutputElementStyle } from './styles';

export const TimeGraphEntry = createNormalizer<TimeGraphEntry>({
end: BigInt,
export const TimeGraphEntrySchema: Schema<TimeGraphEntry> = {
end: bigint,
id: assertNumber,
parentId: assertNumber,
start: BigInt,
style: OutputElementStyle,
});
start: bigint,
};

/**
* Entry in a time graph
Expand All @@ -25,12 +25,11 @@ export interface TimeGraphEntry extends Entry {
end: bigint;
}

const TimeGraphState = createNormalizer<TimeGraphState>({
end: BigInt,
start: BigInt,
const TimeGraphStateSchema: Schema<TimeGraphState> = {
end: bigint,
start: bigint,
tags: assertNumber,
style: OutputElementStyle,
});
};

/**
* Time graph state
Expand Down Expand Up @@ -62,10 +61,10 @@ export interface TimeGraphState {
style?: OutputElementStyle;
}

export const TimeGraphRow = createNormalizer<TimeGraphRow>({
export const TimeGraphRowSchema: Schema<TimeGraphRow> = {
entryId: assertNumber,
states: array(TimeGraphState),
});
states: [TimeGraphStateSchema],
};

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

export const TimeGraphModel = createNormalizer<TimeGraphModel>({
rows: array(TimeGraphRow),
});
export const TimeGraphModelSchema: Schema<TimeGraphModel> = {
rows: [TimeGraphRowSchema],
};

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

export const TimeGraphArrow = createNormalizer<TimeGraphArrow>({
end: BigInt,
export const TimeGraphArrowSchema: Schema<TimeGraphArrow> = {
end: bigint,
sourceId: assertNumber,
start: BigInt,
start: bigint,
targetId: assertNumber,
style: OutputElementStyle,
});
};

/**
* Arrow for time graph
Expand Down
11 changes: 6 additions & 5 deletions tsp-typescript-client/src/models/trace.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { assertNumber, createNormalizer } from '../protocol/serialization';
import { Schema } from 'when-json-met-bigint';
import { assertNumber, bigint } from '../protocol/serialization';

export const Trace = createNormalizer<Trace>({
end: BigInt,
export const TraceSchema: Schema<Trace> = {
end: bigint,
nbEvents: assertNumber,
start: BigInt,
});
start: bigint,
};

/**
* Model of a single trace
Expand Down
19 changes: 10 additions & 9 deletions tsp-typescript-client/src/models/xy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
import { Schema } from 'when-json-met-bigint';
import { assertNumber, number } from '../protocol/serialization';

export const XYSeries = createNormalizer<XYSeries>({
export const XYSeriesSchema: Schema<XYSeries> = {
seriesId: assertNumber,
xValues: array(Number), // lossy conversion if too big
yValues: array(assertNumber),
tags: array(assertNumber),
});
xValues: [number], // lossy conversion if too big
yValues: [assertNumber],
tags: [assertNumber],
};

/**
* Represent a XY series and its values
Expand Down Expand Up @@ -47,9 +48,9 @@ export interface XYSeries {
tags?: number[];
}

export const XYModel = createNormalizer<XYModel>({
series: array(XYSeries),
});
export const XYModelSchema: Schema<XYModel> = {
series: [XYSeriesSchema],
};

/**
* Model of a XY chart, contains at least one XY series
Expand Down
Loading