fix(striker-ui-api): simplify modify query result

main
Tsu-ba-me 2 years ago
parent 1fec480af7
commit 28e12251d6
  1. 14
      striker-ui-api/src/lib/buildQueryResultModifier.ts
  2. 9
      striker-ui-api/src/types/BuildQueryDetailFunction.d.ts
  3. 4
      striker-ui-api/src/types/BuildQueryFunction.d.ts

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

@ -0,0 +1,9 @@
type BuildQueryDetailOptions = { keys?: string[] | '*' };
type BuildQueryDetailReturn = {
query: string;
} & Pick<BuildQueryOptions, 'afterQueryReturn'>;
type BuildQueryDetailFunction = (
options?: BuildQueryDetailOptions,
) => BuildQueryDetailReturn;

@ -1,5 +1,7 @@
type QueryResultModifierFunction = (result: unknown) => unknown;
type BuildQueryOptions = {
afterQueryReturn?: (queryStdout: unknown) => unknown;
afterQueryReturn?: QueryResultModifierFunction;
};
type BuildQueryFunction = (

Loading…
Cancel
Save