d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import type { QueryFunctionContext } from '@tanstack/react-query'
|
|
import { requestJson } from '@/lib/api/client/request'
|
|
import { listWorkflowsContract, type WorkflowListItem } from '@/lib/api/contracts'
|
|
import { type WorkflowQueryScope, workflowKeys } from '@/hooks/queries/utils/workflow-keys'
|
|
import type { WorkflowMetadata } from '@/stores/workflows/registry/types'
|
|
|
|
type WorkflowApiRow = WorkflowListItem
|
|
|
|
export const WORKFLOW_LIST_STALE_TIME = 60 * 1000
|
|
|
|
export function mapWorkflow(workflow: WorkflowApiRow): WorkflowMetadata {
|
|
return {
|
|
id: workflow.id,
|
|
name: workflow.name,
|
|
description: workflow.description ?? undefined,
|
|
workspaceId: workflow.workspaceId ?? undefined,
|
|
folderId: workflow.folderId,
|
|
sortOrder: workflow.sortOrder,
|
|
createdAt: new Date(workflow.createdAt),
|
|
lastModified: new Date(workflow.updatedAt),
|
|
archivedAt: workflow.archivedAt ? new Date(workflow.archivedAt) : null,
|
|
locked: workflow.locked,
|
|
}
|
|
}
|
|
|
|
async function fetchWorkflows(
|
|
workspaceId: string,
|
|
scope: WorkflowQueryScope = 'active',
|
|
signal?: AbortSignal
|
|
): Promise<WorkflowMetadata[]> {
|
|
const { data } = await requestJson(listWorkflowsContract, {
|
|
query: { workspaceId, scope },
|
|
signal,
|
|
})
|
|
return data.map(mapWorkflow)
|
|
}
|
|
|
|
export function getWorkflowListQueryOptions(
|
|
workspaceId: string,
|
|
scope: WorkflowQueryScope = 'active'
|
|
) {
|
|
return {
|
|
queryKey: workflowKeys.list(workspaceId, scope),
|
|
queryFn: ({ signal }: QueryFunctionContext) => fetchWorkflows(workspaceId, scope, signal),
|
|
staleTime: WORKFLOW_LIST_STALE_TIME,
|
|
}
|
|
}
|