Skip to content

Commit

Permalink
The query API now needs its own parameter type
Browse files Browse the repository at this point in the history
This is the only API that needs queryType in its URL
  • Loading branch information
tdeebswihart committed Oct 19, 2023
1 parent f71400c commit fdf372d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/lib/services/query-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { passAccessToken as codecPassAccessToken } from '$lib/stores/data-encoder-config';
import type { WorkflowRouteParameters } from '$lib/types/api';
import type { WorkflowQueryRouteParameters } from '$lib/types/api';
import type { Eventual, Settings } from '$lib/types/global';
import { convertPayloadToJsonWithCodec } from '$lib/utilities/decode-payload';
import {
Expand Down Expand Up @@ -47,12 +47,13 @@ export type ParsedQuery = ReturnType<typeof JSON.parse>[0];
const formatParameters = async (
namespace: string,
workflow: Eventual<{ id: string; runId: string }>,
): Promise<WorkflowRouteParameters> => {
queryType: string,
): Promise<WorkflowQueryRouteParameters> => {
workflow = await workflow;
return {
namespace,
workflowId: workflow.id,
runId: workflow.runId,
queryType,
};
};

Expand All @@ -66,7 +67,7 @@ async function fetchQuery(
}) => void,
): Promise<QueryResponse> {
workflow = await workflow;
const parameters = await formatParameters(namespace, workflow);
const parameters = await formatParameters(namespace, workflow, queryType);
const route = routeForApi('query', parameters);

return await requestFromAPI<QueryResponse>(route, {
Expand All @@ -79,6 +80,7 @@ async function fetchQuery(
},
query: {
queryType,
runId: workflow.runId,
},
}),
},
Expand Down
11 changes: 9 additions & 2 deletions src/lib/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export type WorkflowAPIRoutePath =
| 'workflow.signal'
| 'workflow.reset'
| 'events.ascending'
| 'events.descending'
| 'query';
| 'events.descending';

export type WorkflowQueryAPIRoutePath = 'query';

export type WorkflowActivitiesAPIRoutePath =
| 'activity.complete'
Expand Down Expand Up @@ -43,6 +44,7 @@ export type APIRoutePath =
| TaskQueueAPIRoutePath
| WorkerAPIRoutePath
| WorkflowAPIRoutePath
| WorkflowQueryAPIRoutePath
| WorkflowActivitiesAPIRoutePath
| WorkflowsAPIRoutePath
| NamespaceAPIRoutePath
Expand Down Expand Up @@ -72,6 +74,11 @@ export type WorkflowRouteParameters = Pick<
'namespace' | 'workflowId'
>;

export type WorkflowQueryRouteParameters = Pick<
APIRouteParameters,
'namespace' | 'workflowId' | 'queryType'
>;

export type WorkflowActivitiesRouteParameters = Pick<
APIRouteParameters,
'namespace'
Expand Down
7 changes: 7 additions & 0 deletions src/lib/utilities/route-for-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import type {
WorkflowActivitiesRouteParameters,
WorkflowAPIRoutePath,
WorkflowListRouteParameters,
WorkflowQueryAPIRoutePath,
WorkflowQueryRouteParameters,
WorkflowRouteParameters,
WorkflowsAPIRoutePath,
} from '$lib/types/api';
Expand Down Expand Up @@ -158,6 +160,11 @@ export function routeForApi(
parameters: WorkflowRouteParameters,
shouldEncode?: boolean,
): string;
export function routeForApi(
route: WorkflowQueryAPIRoutePath,
parameters: WorkflowQueryRouteParameters,
shouldEncode?: boolean,
): string;
export function routeForApi(
route: WorkflowActivitiesAPIRoutePath,
parameters: WorkflowActivitiesRouteParameters,
Expand Down

0 comments on commit fdf372d

Please sign in to comment.