Skip to content

Commit

Permalink
Added types for /diary/ services!
Browse files Browse the repository at this point in the history
Many thanks to Jiji for doing the heavy lifting on this one in PR 1061!
- Fixed indents
- Switched ServerData from an interface to a Generic Type. After doing some
further reading, the
[TS Docs](https://www.typescriptlang.org/docs/handbook/2/objects.html#interfaces-vs-intersections)
seem to suggest that this is a better way of handling container-style types.
- Added basic ServerReponse type - this is often how data is wrapped
when returned from functions like `getRawData()`
  • Loading branch information
the-bay-kay committed Oct 20, 2023
1 parent 8d765d0 commit 0bb95b2
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 20 deletions.
75 changes: 75 additions & 0 deletions www/js/types/diaryTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { LocalDt, ServerData } from './serverData'

export type UserInput = ServerData<UserInputData>

export type UserInputData = {
end_ts: number,
start_ts: number
label: string,
start_local_dt?: LocalDt
end_local_dt?: LocalDt
status?: string,
match_id?: string,
}

type ConfirmedPlace = any; // TODO

export type CompositeTrip = {
_id: {$oid: string},
additions: any[], // TODO
cleaned_section_summary: any, // TODO
cleaned_trip: {$oid: string},
confidence_threshold: number,
confirmed_trip: {$oid: string},
distance: number,
duration: number,
end_confirmed_place: ConfirmedPlace,
end_fmt_time: string,
end_loc: {type: string, coordinates: number[]},
end_local_dt: LocalDt,
end_place: {$oid: string},
end_ts: number,
expectation: any, // TODO "{to_label: boolean}"
expected_trip: {$oid: string},
inferred_labels: any[], // TODO
inferred_section_summary: any, // TODO
inferred_trip: {$oid: string},
key: string,
locations: any[], // TODO
origin_key: string,
raw_trip: {$oid: string},
sections: any[], // TODO
source: string,
start_confirmed_place: ConfirmedPlace,
start_fmt_time: string,
start_loc: {type: string, coordinates: number[]},
start_local_dt: LocalDt,
start_place: {$oid: string},
start_ts: number,
user_input: UserInput,
}

export type PopulatedTrip = CompositeTrip & {
additionsList?: any[], // TODO
finalInference?: any, // TODO
geojson?: any, // TODO
getNextEntry?: () => PopulatedTrip | ConfirmedPlace,
userInput?: UserInput,
verifiability?: string,
}

export type Trip = {
end_ts: number,
start_ts: number,
}

export type TlEntry = {
key: string,
origin_key: string,
start_ts: number,
end_ts: number,
enter_ts: number,
exit_ts: number,
duration: number,
getNextEntry?: () => PopulatedTrip | ConfirmedPlace,
}
44 changes: 24 additions & 20 deletions www/js/types/serverData.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
export interface ServerData {
data: any,
metadata: MetaData,
key?: string,
user_id?: { $uuid: string, },
_id?: { $oid: string, },
export type ServerResponse<Type> = {
phone_data: Array<ServerData<Type>>,
}

export type ServerData<Type> = {
data: Type,
metadata: MetaData,
key?: string,
user_id?: { $uuid: string, },
_id?: { $oid: string, },
};

export type MetaData = {
key: string,
platform: string,
write_ts: number,
time_zone: string,
write_fmt_time: string,
write_local_dt: LocalDt,
key: string,
platform: string,
write_ts: number,
time_zone: string,
write_fmt_time: string,
write_local_dt: LocalDt,
};

export type LocalDt = {
minute: number,
hour: number,
second: number,
day: number,
weekday: number,
month: number,
year: number,
timezone: string,
minute: number,
hour: number,
second: number,
day: number,
weekday: number,
month: number,
year: number,
timezone: string,
};

0 comments on commit 0bb95b2

Please sign in to comment.