From 4e335f49f3501ac3a3e51ff34e8702343ac21e06 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 4 May 2023 19:02:31 -0400 Subject: [PATCH] fix(striker-ui-api): add types for query field, row, and result --- striker-ui-api/src/lib/accessModule.ts | 2 +- striker-ui-api/src/lib/buildQueryResultModifier.ts | 6 ++---- .../src/lib/request_handlers/buildGetRequestHandler.ts | 6 ++---- striker-ui-api/src/types/BuildQueryFunction.d.ts | 2 -- striker-ui-api/src/types/QueryResult.d.ts | 5 +++++ striker-ui-api/src/types/QueryResultModifierFunction.d.ts | 1 + 6 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 striker-ui-api/src/types/QueryResult.d.ts create mode 100644 striker-ui-api/src/types/QueryResultModifierFunction.d.ts diff --git a/striker-ui-api/src/lib/accessModule.ts b/striker-ui-api/src/lib/accessModule.ts index 7c7da5c7..57a1e99d 100644 --- a/striker-ui-api/src/lib/accessModule.ts +++ b/striker-ui-api/src/lib/accessModule.ts @@ -167,7 +167,7 @@ const subroutine = async ( return results; }; -const query = (script: string) => +const query = (script: string) => access.interact('r', formatSql(script)); const write = async (script: string) => { diff --git a/striker-ui-api/src/lib/buildQueryResultModifier.ts b/striker-ui-api/src/lib/buildQueryResultModifier.ts index 9f32c641..7f4b24be 100644 --- a/striker-ui-api/src/lib/buildQueryResultModifier.ts +++ b/striker-ui-api/src/lib/buildQueryResultModifier.ts @@ -1,12 +1,10 @@ -type QueryField = string; - export const buildQueryResultModifier = - (mod: (output: QueryField[][]) => T): QueryResultModifierFunction => + (mod: (output: string[][]) => T): QueryResultModifierFunction => (output) => output instanceof Array ? mod(output) : output; export const buildQueryResultReducer = ( - reduce: (previous: T, row: QueryField[]) => T, + reduce: (previous: T, row: string[]) => T, initialValue: T, ) => buildQueryResultModifier((output) => diff --git a/striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts b/striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts index fcb65376..e2cf4b61 100644 --- a/striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts +++ b/striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts @@ -14,7 +14,7 @@ const buildGetRequestHandler = const buildQueryOptions: BuildQueryOptions = {}; - let result: (number | null | string)[][]; + let result: unknown; try { const sqlscript: string = @@ -26,9 +26,7 @@ const buildGetRequestHandler = } catch (queryError) { stderr(`Failed to execute query; CAUSE: ${queryError}`); - response.status(500).send(); - - return; + return response.status(500).send(); } stdoutVar(result, `Query stdout pre-hooks (type=[${typeof result}]): `); diff --git a/striker-ui-api/src/types/BuildQueryFunction.d.ts b/striker-ui-api/src/types/BuildQueryFunction.d.ts index ead3207d..c59e1a34 100644 --- a/striker-ui-api/src/types/BuildQueryFunction.d.ts +++ b/striker-ui-api/src/types/BuildQueryFunction.d.ts @@ -1,5 +1,3 @@ -type QueryResultModifierFunction = (output: unknown) => unknown; - type BuildQueryOptions = { afterQueryReturn?: QueryResultModifierFunction; }; diff --git a/striker-ui-api/src/types/QueryResult.d.ts b/striker-ui-api/src/types/QueryResult.d.ts new file mode 100644 index 00000000..0996cc51 --- /dev/null +++ b/striker-ui-api/src/types/QueryResult.d.ts @@ -0,0 +1,5 @@ +type QueryField = number | null | string; + +type QueryRow = QueryField[]; + +type QueryResult = QueryRow[]; diff --git a/striker-ui-api/src/types/QueryResultModifierFunction.d.ts b/striker-ui-api/src/types/QueryResultModifierFunction.d.ts new file mode 100644 index 00000000..b97744ac --- /dev/null +++ b/striker-ui-api/src/types/QueryResultModifierFunction.d.ts @@ -0,0 +1 @@ +type QueryResultModifierFunction = (output: unknown) => unknown;