Skip to content

Commit

Permalink
Add Prettier to package.json to pin version & rewrite files
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar committed Feb 5, 2024
1 parent fa2f461 commit 1d743a1
Show file tree
Hide file tree
Showing 6 changed files with 15,669 additions and 15,650 deletions.
20 changes: 10 additions & 10 deletions app/analytics/collect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("collectRequestHandler", () => {
[
1, // new visitor
1, // new session
]
],
);
});

Expand All @@ -104,9 +104,9 @@ describe("collectRequestHandler", () => {
// @ts-expect-error - we're mocking the request object
generateRequestParams({
"if-modified-since": new Date(
Date.now() - 5 * 60 * 1000
Date.now() - 5 * 60 * 1000,
).toUTCString(),
})
}),
);

collectRequestHandler(request, env);
Expand All @@ -117,7 +117,7 @@ describe("collectRequestHandler", () => {
[
0, // new visitor
0, // new session
]
],
);
});

Expand All @@ -132,9 +132,9 @@ describe("collectRequestHandler", () => {
// @ts-expect-error - we're mocking the request object
generateRequestParams({
"if-modified-since": new Date(
Date.now() - 31 * 60 * 1000
Date.now() - 31 * 60 * 1000,
).toUTCString(),
})
}),
);

collectRequestHandler(request, env);
Expand All @@ -145,7 +145,7 @@ describe("collectRequestHandler", () => {
[
0, // new visitor
1, // new session
]
],
);
});

Expand All @@ -160,9 +160,9 @@ describe("collectRequestHandler", () => {
// @ts-expect-error - we're mocking the request object
generateRequestParams({
"if-modified-since": new Date(
Date.now() - 60 * 24 * 60 * 1000
Date.now() - 60 * 24 * 60 * 1000,
).toUTCString(),
})
}),
);

collectRequestHandler(request, env);
Expand All @@ -173,7 +173,7 @@ describe("collectRequestHandler", () => {
[
1, // new visitor
1, // new session
]
],
);
});
});
36 changes: 19 additions & 17 deletions app/analytics/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function formatDateString(d: Date) {
function generateEmptyRowsOverInterval(
intervalType: string,
daysAgo: number,
tz?: string
tz?: string,
): [Date, { [key: string]: number }] {
if (!tz) {
tz = "Etc/UTC";
Expand Down Expand Up @@ -96,7 +96,7 @@ function generateEmptyRowsOverInterval(
const rowDate = new Date(i);
// convert to UTC
const utcDateTime = new Date(
rowDate.getTime() + rowDate.getTimezoneOffset() * 60_000
rowDate.getTime() + rowDate.getTimezoneOffset() * 60_000,
);

const key = formatDateString(utcDateTime);
Expand Down Expand Up @@ -151,7 +151,7 @@ export class AnalyticsEngineAPI {
siteId: string,
intervalType: string,
sinceDays: number,
tz?: string
tz?: string,
) {
let intervalCount = 1;

Expand All @@ -167,7 +167,7 @@ export class AnalyticsEngineAPI {
const [startDateTime, initialRows] = generateEmptyRowsOverInterval(
intervalType,
sinceDays,
tz
tz,
);

// NOTE: when using toStartOfInterval, cannot group by other columns
Expand Down Expand Up @@ -217,7 +217,7 @@ export class AnalyticsEngineAPI {
accum[key] = row["count"];
return accum;
},
initialRows
initialRows,
);

// return as sorted array of tuples (i.e. [datetime, count])
Expand All @@ -226,11 +226,11 @@ export class AnalyticsEngineAPI {
if (a[0] < b[0]) return -1;
else if (a[0] > b[0]) return 1;
else return 0;
}
},
);

resolve(sortedRows);
})()
})(),
);
return returnPromise;
}
Expand Down Expand Up @@ -287,7 +287,7 @@ export class AnalyticsEngineAPI {
counts.views += Number(row.count);
});
resolve(counts);
})()
})(),
);

return returnPromise;
Expand All @@ -297,7 +297,7 @@ export class AnalyticsEngineAPI {
siteId: string,
column: T,
sinceDays: number,
limit?: number
limit?: number,
) {
// defaults to 1 day if not specified
const interval = sinceDays || 1;
Expand Down Expand Up @@ -339,9 +339,9 @@ export class AnalyticsEngineAPI {
const key =
row[_column] === "" ? "(none)" : row[_column];
return [key, row["count"]] as const;
})
}),
);
})()
})(),
);
return returnPromise;
}
Expand Down Expand Up @@ -370,7 +370,6 @@ export class AnalyticsEngineAPI {
return this.getVisitorCountByColumn(siteId, "deviceModel", sinceDays);
}


async getSitesOrderedByHits(sinceDays: number, limit?: number) {
// defaults to 1 day if not specified
const interval = sinceDays || 1;
Expand Down Expand Up @@ -404,13 +403,16 @@ export class AnalyticsEngineAPI {

const responseData =
(await response.json()) as AnalyticsQueryResult<SelectionSet>;
const result = responseData.data.reduce((acc, cur) => {
acc.push([cur["siteId"], cur["count"]]);
return acc;
}, [] as [string, number][]);
const result = responseData.data.reduce(
(acc, cur) => {
acc.push([cur["siteId"], cur["count"]]);
return acc;
},
[] as [string, number][],
);

resolve(result);
})()
})(),
);
return returnPromise;
}
Expand Down
6 changes: 3 additions & 3 deletions app/analytics/schema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export type ColumnMappingToType<
T extends (typeof ColumnMappings)[keyof typeof ColumnMappings]
T extends (typeof ColumnMappings)[keyof typeof ColumnMappings],
> = T extends `blob${number}`
? string
: T extends `double${number}`
? number
: never;
? number
: never;

/**
* This maps logical column names to the actual column names in the data store.
Expand Down
4 changes: 2 additions & 2 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async function handleRequest(
// free to delete this parameter in your app if you're not using it!

// eslint-disable-next-line @typescript-eslint/no-unused-vars
loadContext: AppLoadContext
loadContext: AppLoadContext,
) {
const body = await renderToReadableStream(
// @ts-expect-error This is a mistake in the package types, resolved in @remix-run/[email protected]
Expand All @@ -31,7 +31,7 @@ export default async function handleRequest(
console.error(error);
responseStatusCode = 500;
},
}
},
);

if (isbot(request.headers.get("user-agent"))) {
Expand Down
Loading

0 comments on commit 1d743a1

Please sign in to comment.