fix(striker-ui-api): add types for query field, row, and result

main
Tsu-ba-me 2 years ago
parent fc075d778a
commit 4e335f49f3
  1. 2
      striker-ui-api/src/lib/accessModule.ts
  2. 6
      striker-ui-api/src/lib/buildQueryResultModifier.ts
  3. 6
      striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts
  4. 2
      striker-ui-api/src/types/BuildQueryFunction.d.ts
  5. 5
      striker-ui-api/src/types/QueryResult.d.ts
  6. 1
      striker-ui-api/src/types/QueryResultModifierFunction.d.ts

@ -167,7 +167,7 @@ const subroutine = async <T extends unknown[]>(
return results; return results;
}; };
const query = <T extends (number | null | string)[][]>(script: string) => const query = <T extends QueryResult>(script: string) =>
access.interact<T>('r', formatSql(script)); access.interact<T>('r', formatSql(script));
const write = async (script: string) => { const write = async (script: string) => {

@ -1,12 +1,10 @@
type QueryField = string;
export const buildQueryResultModifier = export const buildQueryResultModifier =
<T>(mod: (output: QueryField[][]) => T): QueryResultModifierFunction => <T>(mod: (output: string[][]) => T): QueryResultModifierFunction =>
(output) => (output) =>
output instanceof Array ? mod(output) : output; output instanceof Array ? mod(output) : output;
export const buildQueryResultReducer = <T>( export const buildQueryResultReducer = <T>(
reduce: (previous: T, row: QueryField[]) => T, reduce: (previous: T, row: string[]) => T,
initialValue: T, initialValue: T,
) => ) =>
buildQueryResultModifier<T>((output) => buildQueryResultModifier<T>((output) =>

@ -14,7 +14,7 @@ const buildGetRequestHandler =
const buildQueryOptions: BuildQueryOptions = {}; const buildQueryOptions: BuildQueryOptions = {};
let result: (number | null | string)[][]; let result: unknown;
try { try {
const sqlscript: string = const sqlscript: string =
@ -26,9 +26,7 @@ const buildGetRequestHandler =
} catch (queryError) { } catch (queryError) {
stderr(`Failed to execute query; CAUSE: ${queryError}`); stderr(`Failed to execute query; CAUSE: ${queryError}`);
response.status(500).send(); return response.status(500).send();
return;
} }
stdoutVar(result, `Query stdout pre-hooks (type=[${typeof result}]): `); stdoutVar(result, `Query stdout pre-hooks (type=[${typeof result}]): `);

@ -1,5 +1,3 @@
type QueryResultModifierFunction = (output: unknown) => unknown;
type BuildQueryOptions = { type BuildQueryOptions = {
afterQueryReturn?: QueryResultModifierFunction; afterQueryReturn?: QueryResultModifierFunction;
}; };

@ -0,0 +1,5 @@
type QueryField = number | null | string;
type QueryRow = QueryField[];
type QueryResult = QueryRow[];

@ -0,0 +1 @@
type QueryResultModifierFunction = (output: unknown) => unknown;
Loading…
Cancel
Save