Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"workflows": "esno scripts/workflows.ts",
"audit:tailwind": "esno scripts/audit-tailwind-colors",
"audit:holocene-props": "esno scripts/generate-holocene-props.ts",
"validate:versions": "./scripts/validate-versions.sh"
"validate:versions": "./scripts/validate-versions.sh",
"open-api-typegen": "pnpm dlx swagger2openapi https://raw.githubusercontent.com/temporalio/api/refs/heads/master/openapi/openapiv2.json -o temptemporal.json && pnpm dlx openapi-typescript temptemporal.json -o ./src/lib/utilities/api/temporalio.d.ts && rm ./temptemporal.json"
},
"dependencies": {
"@codemirror/autocomplete": "^6.17.0",
Expand All @@ -84,9 +85,6 @@
"@codemirror/legacy-modes": "^6.4.0",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.29.0",
"@codemirror/lang-java": "^6.0.2",
"@codemirror/lang-go": "^6.0.1",
"@codemirror/lang-php": "^6.0.2",
"@fontsource-variable/inter": "^5.0.8",
"@fontsource/noto-sans-mono": "^5.0.9",
"@lezer/highlight": "^1.1.3",
Expand All @@ -108,6 +106,7 @@
"mdast-util-from-markdown": "^2.0.1",
"mdast-util-to-hast": "^13.2.0",
"monaco-editor": "^0.50.0",
"openapi-fetch": "^0.14.0",
"remark-stringify": "^10.0.3",
"sveltekit-superforms": "^2.26.1",
"tailwind-merge": "^1.14.0",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 62 additions & 2 deletions src/lib/services/batch-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Action } from '$lib/models/workflow-actions';
import { getAuthUser } from '$lib/stores/auth-user';
import { inProgressBatchOperation } from '$lib/stores/batch-operations';
import { temporalVersion } from '$lib/stores/versions';
import { DataClient } from '$lib/utilities/api/fetch';
import type { components } from '$lib/utilities/api/temporalio';
import { stringifyWithBigInt } from '$lib/utilities/parse-with-big-int';
import { requestFromAPI } from '$lib/utilities/request-from-api';
import { routeForApi } from '$lib/utilities/route-for-api';
Expand Down Expand Up @@ -61,6 +63,43 @@ const queryFromWorkflows = (
}, '');
};

// const niceBatchActionToOperation = (
// action: Action,
// resetType?: 'first' | 'last',
// ): NiceStartBatchType => {
// const identity = getAuthUser().email;

// switch (action) {
// case Action.Cancel:
// return {
// cancellationOperation: { identity },
// };
// case Action.Terminate:
// return {
// terminationOperation: { identity },
// };
// case Action.Reset: {
// const options =
// resetType === 'first'
// ? { firstWorkflowTask: {} }
// : { lastWorkflowTask: {} };

// return {
// resetOperation: {
// identity,
// // options is a new field for server versions 1.23 and later
// options,
// // resetType is a deprecated field for server versions 1.23 and earlier
// resetType:
// resetType === 'first'
// ? ResetType.RESET_TYPE_FIRST_WORKFLOW_TASK
// : ResetType.RESET_TYPE_LAST_WORKFLOW_TASK,
// },
// };
// }
// }
// };

const batchActionToOperation = (
action: Action,
resetType?: 'first' | 'last',
Expand Down Expand Up @@ -103,11 +142,14 @@ const toWorkflowExecutionInput = ({
runId,
}: WorkflowExecution): WorkflowExecutionInput => ({ workflowId: id, runId });

type NiceStartBatchType =
components['requestBodies']['WorkflowServiceStartBatchOperationBody']['content']['application/json'];

const createBatchOperationRequest = (
action: Action,
options: CreateBatchOperationOptions,
): StartBatchOperationRequest => {
const body: StartBatchOperationRequest = {
): NiceStartBatchType => {
const body: NiceStartBatchType = {
jobId: options.jobId,
namespace: options.namespace,
reason: options.reason,
Expand Down Expand Up @@ -171,6 +213,24 @@ export async function batchTerminateWorkflows(

const body = createBatchOperationRequest(Action.Terminate, options);

const _: components['requestBodies']['WorkflowServiceStartBatchOperationBody']['content']['application/json'] =
{};
// let thing = typeof body.;

DataClient.POST('/api/v1/namespaces/{namespace}/batch-operations/{jobId}', {
params: {
path: {
jobId: options.jobId,
namespace: options.namespace,
},
},
body: body,
})
.then((data) => {
return data.data;
})
.then(() => {});

await requestFromAPI<null>(route, {
options: {
method: 'POST',
Expand Down
18 changes: 18 additions & 0 deletions src/lib/services/workflow-counts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { CountWorkflowExecutionsResponse } from '$lib/types/workflows';
import { DataClient } from '$lib/utilities/api/fetch';
import { requestFromAPI } from '$lib/utilities/request-from-api';
import { routeForApi } from '$lib/utilities/route-for-api';

Expand Down Expand Up @@ -34,6 +35,23 @@ export const fetchWorkflowCountByExecutionStatus = async ({
query,
}: WorkflowCountByExecutionStatusOptions): Promise<CountWorkflowExecutionsResponse> => {
const groupByClause = 'GROUP BY ExecutionStatus';
return DataClient.GET('/api/v1/namespaces/{namespace}/workflow-count', {
params: {
path: {
namespace,
},
query: {
query,
},
},
})
.then((data) => {
return data.data;
})
.then((data) => {
return { count: data.count, groups };
});

const countRoute = routeForApi('workflows.count', {
namespace,
});
Expand Down
24 changes: 24 additions & 0 deletions src/lib/services/workflow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import type {
WorkflowExecution,
WorkflowIdentifier,
} from '$lib/types/workflows';
import { DataClient } from '$lib/utilities/api/fetch';
import {
cloneAllPotentialPayloadsWithCodec,
decodeSingleReadablePayloadWithCodec,
Expand Down Expand Up @@ -986,6 +987,29 @@ export const fetchPaginatedWorkflows = async (
return (pageSize = 100, token = '') => {
workflowError.set('');

return DataClient.GET('/api/v1/namespaces/{namespace}/workflows', {
params: {
path: {
namespace,
},
query: {
pageSize,
nextPageToken: token,
query,
},
},
})
.then((data) => {
// data.data.executions;
return data.data;
})
.then(({ executions = [], nextPageToken = '' }) => {
return {
items: executions.map((execute) => toWorkflowExecution(execute)),
nextPageToken: nextPageToken ? String(nextPageToken) : '',
};
});

const onError: ErrorCallback = (err) => {
handleUnauthorizedOrForbiddenError(err);

Expand Down
70 changes: 70 additions & 0 deletions src/lib/utilities/api/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import createClient from 'openapi-fetch';

import type { paths } from '../../types/temporalio.d.ts';

// Create the openapi-fetch client with proper typing
export const DataClient = createClient<paths>({
baseUrl: 'https://your-temporal-server', // Update this with your actual server URL
});

/**
* List workflows in a namespace with optional filtering and pagination
*/
export async function listWorkflows(params: {
namespace: string;
pageSize?: number;
nextPageToken?: string;
query?: string;
}) {
const { data, error } = await DataClient.GET(
'/api/v1/namespaces/{namespace}/workflows',
{
params: {
path: { namespace: params.namespace },
query: {
pageSize: params.pageSize,
nextPageToken: params.nextPageToken,
query: params.query,
},
},
},
);

if (error) {
throw new Error(
`Failed to list workflows: ${error.code || 'Unknown error'} - ${error.message || 'No message'}`,
);
}

return data;
}

// DataClient.GET('/api/v1/namespaces/{namespace}', {
// params: {
// path: {
// namespace: 'string',
// },
// },
// });

/**
* Example usage:
*
* // List all workflows in a namespace
* const workflows = await listWorkflows({
* namespace: "default",
* });
*
* // List workflows with pagination
* const paginatedWorkflows = await listWorkflows({
* namespace: "default",
* pageSize: 10,
* nextPageToken: "next-token-here",
* });
*
* // List workflows with filtering
* const filteredWorkflows = await listWorkflows({
* namespace: "default",
* query: "WorkflowType='my-workflow-type'",
* });
*/
Loading