Skip to content

Commit

Permalink
Added types directory, updated TS
Browse files Browse the repository at this point in the history
- While the types themselves may be subject to change, the goal is to
 set up a good foundation for strict typing in the future! As such,
 I added some to a basic version of Jiji's diaryTypes (see PR
 e-mission#1061), and will be updating those regularly.
  • Loading branch information
the-bay-kay committed Oct 19, 2023
1 parent b7abd98 commit e6abae8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
41 changes: 41 additions & 0 deletions www/js/types/diaryTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* This is a draft of diaryTypes, originally added in PR #1061. This file appears
in #1052 as well; these three will most likely be consolidated and rewritten in a
future PR */
export type LocalDt = {
minute: number,
hour: number,
second: number,
day: number,
weekday: number,
month: number,
year: number,
timezone: string,
}

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

export type ServerDataPoint = {
data: any,
metadata: MetaData,
key?: string,
user_id?: { $uuid: string, },
_id?: { $oid: string, },
}

/* These are the objects returned from BEMUserCache calls */
export type ServerData = {
phone_data: Array<ServerDataPoint>
}

export type TimeQuery = {
key: string;
startTs: number;
endTs: number;
}
12 changes: 12 additions & 0 deletions www/js/types/fileShareTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface FsWindow extends Window {
requestFileSystem: (
type: number,
size: number,
successCallback: (fs: any) => void,
errorCallback?: (error: any) => void
) => void;
LocalFileSystem: {
TEMPORARY: number;
PERSISTENT: number;
};
};
28 changes: 5 additions & 23 deletions www/js/unifiedDataLoader.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { logInfo } from './plugin/logger'
import { getRawEntries } from './commHelper';
import { ServerDataPoint, ServerData, TimeQuery } from './types/diaryTypes'

interface dataObj {
data: any;
metadata: {
plugin: string;
write_ts: number;
platform: string;
read_ts: number;
key: string;
type: string;
}
}
/**
* combineWithDedup is a helper function for combinedPromises
* @param list1 values evaluated from a BEMUserCache promise
* @param list2 same as list1
* @returns a dedup array generated from the input lists
*/
const combineWithDedup = function(list1: Array<dataObj>, list2: Array<dataObj>) {
const combineWithDedup = function(list1: Array<ServerDataPoint>, list2: Array<ServerDataPoint>) {
const combinedList = list1.concat(list2);
return combinedList.filter(function(value, i, array) {
const firstIndexOfValue = array.findIndex(function(element) {
Expand Down Expand Up @@ -91,27 +81,19 @@ const combinedPromises = function(promiseList: Array<Promise<any>>,
});
};

interface serverData {
phone_data: Array<any>;
}
interface tQ {
key: string;
startTs: number;
endTs: number;
}
/**
* getUnifiedDataForInterval is a generalized method to fetch data by its timestamps
* @param key string corresponding to a data entry
* @param tq an object that contains interval start and end times
* @param getMethod a BEMUserCache method that fetches certain data via a promise
* @returns A promise that evaluates to the all values found within the queried data
*/
export const getUnifiedDataForInterval = function(key: string, tq: tQ,
getMethod: (key: string, tq: tQ, flag: boolean) => Promise<any>) {
export const getUnifiedDataForInterval = function(key: string, tq: TimeQuery,
getMethod: (key: string, tq: TimeQuery, flag: boolean) => Promise<any>) {
const test = true;
const localPromise = getMethod(key, tq, test);
const remotePromise = getRawEntries([key], tq.startTs, tq.endTs)
.then(function(serverResponse: serverData) {
.then(function(serverResponse: ServerData) {
return serverResponse.phone_data;
});
var promiseList = [localPromise, remotePromise]
Expand Down

0 comments on commit e6abae8

Please sign in to comment.