Skip to content

Commit

Permalink
Updated Object Types
Browse files Browse the repository at this point in the history
- Updated types to match PR e-mission#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.
  • Loading branch information
the-bay-kay committed Oct 26, 2023
1 parent 46c1429 commit f0da5ea
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 44 deletions.
6 changes: 3 additions & 3 deletions www/__tests__/unifiedDataLoader.test.ts
Original file line number Diff line number Diff line change
@@ -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<any> = {
data: '',
metadata: {
key: '',
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('combineWithDedup can', () => {
});

// combinedPromises tests
const promiseGenerator = (values: Array<ServerDataPoint>) => {
const promiseGenerator = (values: Array<ServerData<any>>) => {
return Promise.resolve(values);
};

Expand Down
12 changes: 0 additions & 12 deletions www/js/types/fileShareTypes.ts

This file was deleted.

48 changes: 22 additions & 26 deletions www/js/types/diaryTypes.ts → www/js/types/serverData.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
/* 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<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,
}

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 LocalDt = {
minute: number,
hour: number,
second: number,
day: number,
weekday: number,
month: number,
year: number,
timezone: string,
};

export type TimeQuery = {
key: string;
Expand Down
6 changes: 3 additions & 3 deletions www/js/unifiedDataLoader.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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
* @param list1 values evaluated from a BEMUserCache promise
* @param list2 same as list1
* @returns a dedup array generated from the input lists
*/
export const combineWithDedup = function(list1: Array<ServerDataPoint>, list2: Array<ServerDataPoint>) {
export const combineWithDedup = function(list1: Array<ServerData<any>>, list2: Array<any>) {
const combinedList = list1.concat(list2);
return combinedList.filter(function(value, i, array) {
const firstIndexOfValue = array.findIndex(function(element) {
Expand Down Expand Up @@ -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<any>) {
return serverResponse.phone_data;
});
var promiseList = [getPromise, remotePromise]
Expand Down

0 comments on commit f0da5ea

Please sign in to comment.