From f0da5eaa5f833c21e04ee8a4cc7cd57e49ab4fe9 Mon Sep 17 00:00:00 2001 From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:02:37 -0700 Subject: [PATCH] Updated Object Types - Updated types to match PR #1073 - Part of the motivaiton for this is that `/dairy/services.js` also relies on unifiedDataLoader; if this is written using those types, then that rewrite can build off of this rewrite without any additional merge conflicts down the road. --- www/__tests__/unifiedDataLoader.test.ts | 6 +-- www/js/types/fileShareTypes.ts | 12 ----- www/js/types/{diaryTypes.ts => serverData.ts} | 48 +++++++++---------- www/js/unifiedDataLoader.ts | 6 +-- 4 files changed, 28 insertions(+), 44 deletions(-) delete mode 100644 www/js/types/fileShareTypes.ts rename www/js/types/{diaryTypes.ts => serverData.ts} (57%) diff --git a/www/__tests__/unifiedDataLoader.test.ts b/www/__tests__/unifiedDataLoader.test.ts index 5db23982b..34f98bcd1 100644 --- a/www/__tests__/unifiedDataLoader.test.ts +++ b/www/__tests__/unifiedDataLoader.test.ts @@ -1,10 +1,10 @@ import { mockLogger } from '../__mocks__/globalMocks'; import { combineWithDedup, combinedPromises } from '../js/unifiedDataLoader'; -import { ServerDataPoint } from '../js/types/diaryTypes'; +import { ServerData } from '../js/types/serverData'; mockLogger(); -const testOne: ServerDataPoint = { +const testOne: ServerData = { data: '', metadata: { key: '', @@ -46,7 +46,7 @@ describe('combineWithDedup can', () => { }); // combinedPromises tests -const promiseGenerator = (values: Array) => { +const promiseGenerator = (values: Array>) => { return Promise.resolve(values); }; diff --git a/www/js/types/fileShareTypes.ts b/www/js/types/fileShareTypes.ts deleted file mode 100644 index 7f0354f8c..000000000 --- a/www/js/types/fileShareTypes.ts +++ /dev/null @@ -1,12 +0,0 @@ -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/types/diaryTypes.ts b/www/js/types/serverData.ts similarity index 57% rename from www/js/types/diaryTypes.ts rename to www/js/types/serverData.ts index 142629000..9f274992c 100644 --- a/www/js/types/diaryTypes.ts +++ b/www/js/types/serverData.ts @@ -1,17 +1,15 @@ -/* 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 ServerResponse = { + phone_data: Array>, } +export type ServerData = { + data: Type, + metadata: MetaData, + key?: string, + user_id?: { $uuid: string, }, + _id?: { $oid: string, }, +}; + export type MetaData = { key: string, platform: string, @@ -19,20 +17,18 @@ export type MetaData = { 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 LocalDt = { + minute: number, + hour: number, + second: number, + day: number, + weekday: number, + month: number, + year: number, + timezone: string, +}; export type TimeQuery = { key: string; diff --git a/www/js/unifiedDataLoader.ts b/www/js/unifiedDataLoader.ts index 81b156c7a..15bcd341d 100644 --- a/www/js/unifiedDataLoader.ts +++ b/www/js/unifiedDataLoader.ts @@ -1,6 +1,6 @@ import { logDebug } from './plugin/logger' import { getRawEntries } from './commHelper'; -import { ServerDataPoint, ServerData, TimeQuery } from './types/diaryTypes' +import { ServerResponse, ServerData, TimeQuery } from './types/serverData'; /** * combineWithDedup is a helper function for combinedPromises @@ -8,7 +8,7 @@ import { ServerDataPoint, ServerData, TimeQuery } from './types/diaryTypes' * @param list2 same as list1 * @returns a dedup array generated from the input lists */ -export const combineWithDedup = function(list1: Array, list2: Array) { +export 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) { @@ -95,7 +95,7 @@ export const getUnifiedDataForInterval = function(key: string, tq: TimeQuery, const test = true; const getPromise = getMethod(key, tq, test); const remotePromise = getRawEntries([key], tq.startTs, tq.endTs) - .then(function(serverResponse: ServerData) { + .then(function(serverResponse: ServerResponse) { return serverResponse.phone_data; }); var promiseList = [getPromise, remotePromise]