Skip to content

Commit

Permalink
fix: resurrect the command line query utility
Browse files Browse the repository at this point in the history
  • Loading branch information
tkurki committed Nov 7, 2023
1 parent 648de8a commit daedd80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
18 changes: 13 additions & 5 deletions src/HistoryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ interface SimpleResponse {
status: (s: number) => void
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
json: (j: any) => void
header: (n: string, v: string) => void
send: (c: string) => void
}

interface SimpleRequest {
Expand All @@ -97,7 +99,7 @@ function getPositions(
format: string,
timeResolutionMillis: number,
debug: (s: string) => void,
res: Response,
res: SimpleResponse,
) {
const query = `
select
Expand Down Expand Up @@ -141,7 +143,7 @@ export function getValues(
format: string,
debug: (s: string) => void,
req: SimpleRequest,
res: Response,
res: SimpleResponse,
) {
const start = Date.now()
const timeResolutionMillis =
Expand Down Expand Up @@ -356,7 +358,7 @@ function splitPathExpression(pathExpression: string): PathSpec {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function outputPositionsGpx(rows: any[], context: string, res: Response) {
function outputPositionsGpx(rows: any[], context: string, res: SimpleResponse) {
let responseBody = `<?xml version="1.0" encoding="UTF-8" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="signalk-to-influxdb2">
<metadata><author>${context}</author></metadata>
Expand Down Expand Up @@ -386,7 +388,13 @@ function outputPositionsGpx(rows: any[], context: string, res: Response) {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function outputPositionsJson(rows: any[], context: string, from: ZonedDateTime, to: ZonedDateTime, res: Response) {
function outputPositionsJson(
rows: any[],
context: string,
from: ZonedDateTime,
to: ZonedDateTime,
res: SimpleResponse,
) {
const resultData = rows.map((row) => {
return [row.time.toISOString(), [row.lon, row.lat]]
})
Expand All @@ -401,7 +409,7 @@ function outputPositionsJson(rows: any[], context: string, from: ZonedDateTime,
})
}

function outputError(res: Response, status: number, detail: string) {
function outputError(res: SimpleResponse, status: number, detail: string) {
res.status(status)
res.json({
status: status.toString(),
Expand Down
12 changes: 7 additions & 5 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ const req = {
resolution: '60s',
},
}
// const resp = {
// status: (n: number) => undefined,
// json: (s: any) => console.log(JSON.stringify(s, null, 2)),
// }
//getValues(skinflux, context, start, end, format, toConsole, req, resp)
const resp = {
status: (n: number) => undefined,
json: (s: any) => console.log(JSON.stringify(s, null, 2)),
header: (n: string, v: string) => console.log(`${n}:${v}`),
send: (c: string) => console.log(c),
}
getValues(skinflux, context, start, end, format, toConsole, req, resp)

0 comments on commit daedd80

Please sign in to comment.