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
163 lines
4.9 KiB
TypeScript
163 lines
4.9 KiB
TypeScript
import { TableIcon } from '@/components/icons'
|
|
import { requestJson } from '@/lib/api/client/request'
|
|
import { listTablesContract } from '@/lib/api/contracts/tables'
|
|
import type { TableDefinition } from '@/lib/table'
|
|
import { getQueryClient } from '@/app/_shell/providers/get-query-client'
|
|
import { tableKeys } from '@/hooks/queries/utils/table-keys'
|
|
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
|
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
|
|
import type { TriggerConfig } from '@/triggers/types'
|
|
|
|
async function fetchTableColumns(blockId: string): Promise<Array<{ label: string; id: string }>> {
|
|
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
|
|
const workspaceId = useWorkflowRegistry.getState().hydration.workspaceId
|
|
if (!activeWorkflowId || !workspaceId) return []
|
|
|
|
const blockValues = useSubBlockStore.getState().workflowValues[activeWorkflowId]?.[blockId]
|
|
const tableId = (blockValues?.tableSelector as string) || (blockValues?.manualTableId as string)
|
|
if (!tableId) return []
|
|
|
|
const tables = await getQueryClient().fetchQuery({
|
|
queryKey: tableKeys.list(workspaceId),
|
|
queryFn: async ({ signal }): Promise<TableDefinition[]> => {
|
|
const response = await requestJson(listTablesContract, {
|
|
query: { workspaceId, scope: 'active' },
|
|
signal,
|
|
})
|
|
return (response.data.tables ?? []) as TableDefinition[]
|
|
},
|
|
staleTime: 60 * 1000,
|
|
})
|
|
|
|
const table = tables.find((t: TableDefinition) => t.id === tableId)
|
|
if (!table?.schema?.columns) return []
|
|
|
|
return table.schema.columns.map((col) => ({ id: col.name, label: col.name }))
|
|
}
|
|
|
|
export const tableNewRowTrigger: TriggerConfig = {
|
|
id: 'table_new_row',
|
|
name: 'Table Trigger',
|
|
provider: 'table',
|
|
description: 'Triggers when rows are inserted or updated in a table',
|
|
version: '1.0.0',
|
|
icon: TableIcon,
|
|
|
|
subBlocks: [
|
|
{
|
|
id: 'tableSelector',
|
|
title: 'Table',
|
|
type: 'table-selector',
|
|
description: 'The table to monitor.',
|
|
required: true,
|
|
mode: 'trigger',
|
|
canonicalParamId: 'tableId',
|
|
placeholder: 'Select a table',
|
|
},
|
|
{
|
|
id: 'manualTableId',
|
|
title: 'Table ID',
|
|
type: 'short-input',
|
|
placeholder: 'Enter table ID',
|
|
description: 'The table to monitor.',
|
|
required: true,
|
|
mode: 'trigger-advanced',
|
|
canonicalParamId: 'tableId',
|
|
},
|
|
{
|
|
id: 'eventType',
|
|
title: 'Event',
|
|
type: 'dropdown',
|
|
options: [
|
|
{ id: 'insert', label: 'Row Inserted' },
|
|
{ id: 'update', label: 'Row Updated' },
|
|
],
|
|
defaultValue: 'insert',
|
|
description: 'The type of event to trigger on.',
|
|
required: true,
|
|
mode: 'trigger',
|
|
},
|
|
{
|
|
id: 'watchColumns',
|
|
title: 'Watch Columns',
|
|
type: 'dropdown',
|
|
multiSelect: true,
|
|
options: [],
|
|
placeholder: 'All columns',
|
|
description: 'Only fire when these columns change. Leave empty to fire on any update.',
|
|
required: false,
|
|
mode: 'trigger',
|
|
condition: { field: 'eventType', value: 'update' },
|
|
dependsOn: { any: ['tableSelector', 'manualTableId'] },
|
|
fetchOptions: fetchTableColumns,
|
|
},
|
|
{
|
|
id: 'includeHeaders',
|
|
title: 'Map Row Values to Headers',
|
|
type: 'switch',
|
|
defaultValue: true,
|
|
description:
|
|
'When enabled, each row is returned as a key-value object mapped to column names.',
|
|
required: false,
|
|
mode: 'trigger',
|
|
},
|
|
{
|
|
id: 'triggerInstructions',
|
|
title: 'Setup Instructions',
|
|
hideFromPreview: true,
|
|
type: 'text',
|
|
defaultValue: [
|
|
'Select the table to monitor',
|
|
'Choose whether to trigger on row inserts or updates',
|
|
'For updates, optionally select specific columns to watch',
|
|
'The workflow will trigger automatically when the event occurs',
|
|
]
|
|
.map(
|
|
(instruction, index) =>
|
|
`<div class="mb-3"><strong>${index + 1}.</strong> ${instruction}</div>`
|
|
)
|
|
.join(''),
|
|
mode: 'trigger',
|
|
},
|
|
],
|
|
|
|
outputs: {
|
|
row: {
|
|
type: 'json',
|
|
description: 'Row data mapped to column names (when header mapping is enabled)',
|
|
},
|
|
rawRow: {
|
|
type: 'json',
|
|
description: 'Raw row data object',
|
|
},
|
|
previousRow: {
|
|
type: 'json',
|
|
description: 'Previous row data before the update (null for inserts)',
|
|
},
|
|
changedColumns: {
|
|
type: 'json',
|
|
description: 'List of column names that changed (empty for inserts)',
|
|
},
|
|
rowId: {
|
|
type: 'string',
|
|
description: 'The unique row ID',
|
|
},
|
|
headers: {
|
|
type: 'json',
|
|
description: 'Column names from the table schema',
|
|
},
|
|
tableId: {
|
|
type: 'string',
|
|
description: 'The table ID',
|
|
},
|
|
tableName: {
|
|
type: 'string',
|
|
description: 'The table name',
|
|
},
|
|
timestamp: {
|
|
type: 'string',
|
|
description: 'Event timestamp in ISO format',
|
|
},
|
|
},
|
|
}
|