From e6abae8396da8cc08a88618b8ae16371639bfa07 Mon Sep 17 00:00:00 2001 From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:40:09 -0700 Subject: [PATCH] Added `types` directory, updated TS - 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 #1061), and will be updating those regularly. --- www/js/types/diaryTypes.ts | 41 ++++++++++++++++++++++++++++++++++ www/js/types/fileShareTypes.ts | 12 ++++++++++ www/js/unifiedDataLoader.ts | 28 +++++------------------ 3 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 www/js/types/diaryTypes.ts create mode 100644 www/js/types/fileShareTypes.ts diff --git a/www/js/types/diaryTypes.ts b/www/js/types/diaryTypes.ts new file mode 100644 index 000000000..142629000 --- /dev/null +++ b/www/js/types/diaryTypes.ts @@ -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 +} + +export type TimeQuery = { + key: string; + startTs: number; + endTs: number; +} \ No newline at end of file diff --git a/www/js/types/fileShareTypes.ts b/www/js/types/fileShareTypes.ts new file mode 100644 index 000000000..7f0354f8c --- /dev/null +++ b/www/js/types/fileShareTypes.ts @@ -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; + }; +}; diff --git a/www/js/unifiedDataLoader.ts b/www/js/unifiedDataLoader.ts index 379c30165..f2e8c672c 100644 --- a/www/js/unifiedDataLoader.ts +++ b/www/js/unifiedDataLoader.ts @@ -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, list2: Array) { +const combineWithDedup = function(list1: Array, list2: Array) { const combinedList = list1.concat(list2); return combinedList.filter(function(value, i, array) { const firstIndexOfValue = array.findIndex(function(element) { @@ -91,14 +81,6 @@ const combinedPromises = function(promiseList: Array>, }); }; -interface serverData { - phone_data: Array; -} -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 @@ -106,12 +88,12 @@ interface tQ { * @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) { +export const getUnifiedDataForInterval = function(key: string, tq: TimeQuery, + getMethod: (key: string, tq: TimeQuery, flag: boolean) => Promise) { 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]