Skip to content

Commit

Permalink
Updated types to match UnifiedDataLoader, PR e-mission#1073
Browse files Browse the repository at this point in the history
  • Loading branch information
the-bay-kay committed Oct 27, 2023
1 parent f0da15e commit 5e61cb9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
9 changes: 5 additions & 4 deletions www/__tests__/controlHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mockLogger } from "../__mocks__/globalMocks";
import { createWriteFile } from "../js/controlHelper";
import { FsWindow, RawData, RawDataCluster } from "../js/types/fileShareTypes"
import { FsWindow } from "../js/types/fileShareTypes"
import { ServerData, ServerResponse} from "../js/types/serverData"

mockLogger();
declare let window: FsWindow;
Expand All @@ -14,7 +15,7 @@ const generateFakeValues = (arraySize: number) => {
if (arraySize <= 0)
return new Promise (() => {return []});

const sampleDataObj : RawData = {
const sampleDataObj : ServerData<any>= {
data: {
name: 'testValue #',
ts: 1234567890.9876543,
Expand Down Expand Up @@ -51,14 +52,14 @@ const generateFakeValues = (arraySize: number) => {
values[index].data.name = element.data.name + index.toString()
});

return new Promise<RawDataCluster>(() => {
return new Promise<ServerResponse<any>>(() => {
return { phone_data: values };
});
};

// A variation of createShareData; confirms the file has been written,
// without calling the sharing components
const confirmFileExists = (fileName: string, dataCluster: RawDataCluster) => {
const confirmFileExists = (fileName: string, dataCluster: ServerResponse<any>) => {
return function() {
return new Promise(function() {
window.requestFileSystem(window.LocalFileSystem.TEMPORARY, 0, function(fs) {
Expand Down
5 changes: 3 additions & 2 deletions www/js/controlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { DateTime } from "luxon";

import { getRawEntries } from "./commHelper";
import { logInfo, displayError, logDebug } from "./plugin/logger";
import { FsWindow, RawDataCluster } from "./types/fileShareTypes"
import { FsWindow } from "./types/fileShareTypes"
import { ServerResponse} from "./types/serverData";
import i18next from "./i18nextInit" ;

declare let window: FsWindow;
Expand All @@ -13,7 +14,7 @@ declare let window: FsWindow;
* @returns a function that returns a promise, which writes the file upon evaluation.
*/
export const createWriteFile = function (fileName: string) {
return function(result: RawDataCluster) {
return function(result: ServerResponse<any>) {
const resultList = result.phone_data;
return new Promise<void>(function(resolve, reject) {
window.requestFileSystem(window.LocalFileSystem.TEMPORARY, 0, function(fs) {
Expand Down
12 changes: 0 additions & 12 deletions www/js/types/diaryTypes.ts

This file was deleted.

39 changes: 9 additions & 30 deletions www/js/types/fileShareTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { LocalDt } from "./diaryTypes";
import { ServerData } from './serverData';

export type TimeStampData = ServerData<RawTimelineData>;

export type RawTimelineData = {
name: string,
ts: number,
reading: number,
};

export interface FsWindow extends Window {
requestFileSystem: (
Expand All @@ -12,32 +20,3 @@ export interface FsWindow extends Window {
PERSISTENT: number;
};
};

/* These are the objects returned from getRawEnteries when it is called by
the getMyData() method. */
export interface RawDataCluster {
phone_data: Array<RawData>
}

export interface RawData {
data: {
name: string,
ts: number,
reading: number,
},
metadata: {
key: string,
platform: string,
write_ts: number,
time_zone: string,
write_fmt_time: string,
write_local_dt: LocalDt,
},
user_id: {
$uuid: string,
},
_id: {
$oid: string,
}
}

32 changes: 32 additions & 0 deletions www/js/types/serverData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 LocalDt = {
minute: number,
hour: number,
second: number,
day: number,
weekday: number,
month: number,
year: number,
timezone: string,
};

0 comments on commit 5e61cb9

Please sign in to comment.