Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ vi.mock('@sim/utils/id', () => ({
generateId: vi.fn().mockReturnValue('job-id-xyz'),
generateShortId: vi.fn().mockReturnValue('short-id'),
}))
vi.mock('@/lib/table/service', () => ({
vi.mock('@/lib/table/jobs/service', () => ({
markTableJobRunning: mockMarkTableJobRunning,
releaseJobClaim: mockReleaseJobClaim,
}))
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/delete-async/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { runDetached } from '@/lib/core/utils/background'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { markTableDeleteFailed, runTableDelete } from '@/lib/table/delete-runner'
import { markTableJobRunning, releaseJobClaim } from '@/lib/table/service'
import { markTableJobRunning, releaseJobClaim } from '@/lib/table/jobs/service'
import type { TableDeleteJobPayload } from '@/lib/table/types'
import { accessError, checkAccess, tableFilterError } from '@/app/api/table/utils'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vi.mock('@sim/utils/id', () => ({
generateId: vi.fn().mockReturnValue('job-id-xyz'),
generateShortId: vi.fn().mockReturnValue('short-id'),
}))
vi.mock('@/lib/table/service', () => ({ markTableJobRunning: mockMarkTableJobRunning }))
vi.mock('@/lib/table/jobs/service', () => ({ markTableJobRunning: mockMarkTableJobRunning }))
vi.mock('@/lib/table/export-runner', () => ({ runTableExport: mockRunTableExport }))
vi.mock('@/lib/core/utils/background', () => ({
runDetached: (_label: string, work: () => Promise<unknown>) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/export-async/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { runDetached } from '@/lib/core/utils/background'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { runTableExport, type TableExportPayload } from '@/lib/table/export-runner'
import { markTableJobRunning, releaseJobClaim } from '@/lib/table/service'
import { markTableJobRunning, releaseJobClaim } from '@/lib/table/jobs/service'
import type { TableExportJobPayload } from '@/lib/table/types'
import { accessError, checkAccess } from '@/app/api/table/utils'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { mockCheckAccess, mockGetTableJob, mockGeneratePresignedDownloadUrl } = v
mockGeneratePresignedDownloadUrl: vi.fn(),
}))

vi.mock('@/lib/table/service', () => ({ getTableJob: mockGetTableJob }))
vi.mock('@/lib/table/jobs/service', () => ({ getTableJob: mockGetTableJob }))
vi.mock('@/lib/uploads/core/storage-service', () => ({
generatePresignedDownloadUrl: mockGeneratePresignedDownloadUrl,
}))
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/export/download/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseRequest } from '@/lib/api/server'
import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { getTableJob } from '@/lib/table/service'
import { getTableJob } from '@/lib/table/jobs/service'
import type { TableExportJobPayload } from '@/lib/table/types'
import { generatePresignedDownloadUrl } from '@/lib/uploads/core/storage-service'
import { accessError, checkAccess } from '@/app/api/table/utils'
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/export/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vi.mock('@/app/api/table/utils', async () => {
}
})

vi.mock('@/lib/table/service', () => ({
vi.mock('@/lib/table/rows/service', () => ({
queryRows: mockQueryRows,
}))

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/export/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { neutralizeCsvFormula } from '@/lib/core/utils/csv'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { buildNameById, getColumnId, rowDataIdToName } from '@/lib/table/column-keys'
import { queryRows } from '@/lib/table/service'
import { queryRows } from '@/lib/table/rows/service'
import { accessError, checkAccess } from '@/app/api/table/utils'

const logger = createLogger('TableExport')
Expand Down
6 changes: 5 additions & 1 deletion apps/sim/app/api/table/[tableId]/groups/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { parseRequest } from '@/lib/api/server'
import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { addWorkflowGroup, deleteWorkflowGroup, updateWorkflowGroup } from '@/lib/table/service'
import {
addWorkflowGroup,
deleteWorkflowGroup,
updateWorkflowGroup,
} from '@/lib/table/workflow-groups/service'
import { accessError, checkAccess, normalizeColumn } from '@/app/api/table/utils'

const logger = createLogger('TableWorkflowGroupsAPI')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vi.mock('@sim/utils/id', () => ({
generateId: vi.fn().mockReturnValue('import-id-xyz'),
generateShortId: vi.fn().mockReturnValue('short-id'),
}))
vi.mock('@/lib/table/service', () => ({ markTableJobRunning: mockMarkTableImporting }))
vi.mock('@/lib/table/jobs/service', () => ({ markTableJobRunning: mockMarkTableImporting }))
vi.mock('@/lib/table/import-runner', () => ({ runTableImport: mockRunTableImport }))
vi.mock('@/lib/core/utils/background', () => ({
runDetached: (_label: string, work: () => Promise<unknown>) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/import-async/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { runDetached } from '@/lib/core/utils/background'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { runTableImport, type TableImportPayload } from '@/lib/table/import-runner'
import { markTableJobRunning, releaseJobClaim } from '@/lib/table/service'
import { markTableJobRunning, releaseJobClaim } from '@/lib/table/jobs/service'
import { accessError, checkAccess } from '@/app/api/table/utils'

const logger = createLogger('TableImportIntoAsync')
Expand Down
20 changes: 13 additions & 7 deletions apps/sim/app/api/table/[tableId]/import/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,26 @@ vi.mock('@/app/api/table/utils', async () => {
})

/**
* The route imports `importAppendRows` / `importReplaceRows` from the barrel,
* which forwards them from `./service`. These functions own the import
* transaction (column adds + row writes); mocking the service module replaces
* them without touching the other real helpers (`coerceRowsForTable`,
* `createCsvParser`, etc.) exported through the barrel.
* The route imports `importAppendRows` / `importReplaceRows` from
* `@/lib/table/import-data`. These functions own the import transaction (column
* adds + row writes); mocking that module replaces them without touching the
* other real helpers (`coerceRowsForTable`, `createCsvParser`, etc.) exported
* through the barrel.
*/
vi.mock('@/lib/table/service', () => ({
vi.mock('@/lib/table/import-data', () => ({
importAppendRows: mockImportAppendRows,
importReplaceRows: mockImportReplaceRows,
dispatchAfterBatchInsert: mockDispatchAfterBatchInsert,
}))

vi.mock('@/lib/table/jobs/service', () => ({
markTableJobRunning: mockMarkTableImporting,
releaseJobClaim: mockReleaseImportClaim,
}))

vi.mock('@/lib/table/rows/service', () => ({
dispatchAfterBatchInsert: mockDispatchAfterBatchInsert,
}))

import { POST } from '@/app/api/table/[tableId]/import/route'

function createCsvFile(contents: string, name = 'data.csv', type = 'text/csv'): File {
Expand Down
3 changes: 1 addition & 2 deletions apps/sim/app/api/table/[tableId]/import/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import {
createCsvParser,
dispatchAfterBatchInsert,
generateColumnId,
importAppendRows,
importReplaceRows,
inferColumnType,
markTableJobRunning,
releaseJobClaim,
Expand All @@ -35,6 +33,7 @@ import {
type TableSchema,
validateMapping,
} from '@/lib/table'
import { importAppendRows, importReplaceRows } from '@/lib/table/import-data'
import {
accessError,
checkAccess,
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/job/cancel/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { mockCheckAccess, mockMarkJobCanceled, mockGetTableJob, mockAppendTableEv
})
)

vi.mock('@/lib/table/service', () => ({
vi.mock('@/lib/table/jobs/service', () => ({
markJobCanceled: mockMarkJobCanceled,
getTableJob: mockGetTableJob,
}))
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/job/cancel/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { appendTableEvent } from '@/lib/table/events'
import { getTableJob, markJobCanceled } from '@/lib/table/service'
import { getTableJob, markJobCanceled } from '@/lib/table/jobs/service'
import type { TableJobType } from '@/lib/table/types'
import { accessError, checkAccess } from '@/app/api/table/utils'

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/rows/find/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ vi.mock('@/app/api/table/utils', async () => {
}
})

vi.mock('@/lib/table/service', () => ({
vi.mock('@/lib/table/rows/service', () => ({
findRowMatches: mockFindRowMatches,
}))

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/rows/find/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import type { Sort } from '@/lib/table'
import { findRowMatches } from '@/lib/table/service'
import { findRowMatches } from '@/lib/table/rows/service'
import { TableQueryValidationError } from '@/lib/table/sql'
import { accessError, checkAccess } from '@/app/api/table/utils'

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/rows/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ vi.mock('@/lib/table', async () => {
}
})

vi.mock('@/lib/table/service', () => ({
vi.mock('@/lib/table/rows/service', () => ({
queryRows: mockQueryRows,
}))

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/[tableId]/rows/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
validateRowData,
validateRowSize,
} from '@/lib/table'
import { queryRows } from '@/lib/table/service'
import { queryRows } from '@/lib/table/rows/service'
import { TableQueryValidationError } from '@/lib/table/sql'
import { rowWireTranslators } from '@/app/api/table/row-wire'
import { accessError, checkAccess, rowWriteErrorResponse } from '@/app/api/table/utils'
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/app/api/table/import-csv/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ vi.mock('@sim/utils/id', () => ({
// streaming multipart + CSV pipeline is exercised end-to-end.
vi.mock('@/lib/table/service', () => ({
createTable: mockCreateTable,
batchInsertRows: mockBatchInsertRows,
deleteTable: mockDeleteTable,
}))

vi.mock('@/lib/table/rows/service', () => ({
batchInsertRows: mockBatchInsertRows,
}))
vi.mock('@/lib/table/billing', () => ({ getWorkspaceTableLimits: mockGetLimits }))
vi.mock('@/app/api/table/utils', async () => {
const { NextResponse } = await import('next/server')
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/table/jobs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseRequest } from '@/lib/api/server'
import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { listWorkspaceExportJobs } from '@/lib/table/service'
import { listWorkspaceExportJobs } from '@/lib/table/jobs/service'
import { checkWorkspaceAccess } from '@/lib/workspaces/permissions/utils'

const logger = createLogger('TableJobsAPI')
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/v1/tables/[tableId]/rows/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
validateRowData,
validateRowSize,
} from '@/lib/table'
import { queryRows } from '@/lib/table/service'
import { queryRows } from '@/lib/table/rows/service'
import { TableQueryValidationError } from '@/lib/table/sql'
import { accessError, checkAccess, rowWriteErrorResponse } from '@/app/api/table/utils'
import {
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/background/resume-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function executeResumeJob(payload: ResumeExecutionPayload) {
// philosophy). Aborting here also stops the wasted compute the guard alone
// can't prevent. Read the cell's current exec and bail if cancelled.
if (cellContext) {
const { getRowById } = await import('@/lib/table/service')
const { getRowById } = await import('@/lib/table/rows/service')
const cellRow = await getRowById(
cellContext.tableId,
cellContext.rowId,
Expand Down Expand Up @@ -323,7 +323,8 @@ async function continueCascadeAfterResume(cellContext: {
workspaceId: string
groupId: string
}): Promise<void> {
const { getTableById, getRowById } = await import('@/lib/table/service')
const { getTableById } = await import('@/lib/table/service')
const { getRowById } = await import('@/lib/table/rows/service')
const { pickNextEligibleGroupForRow } = await import('@/lib/table/workflow-columns')
const { runRowCascadeLoop } = await import('@/background/workflow-column-execution')

Expand Down
12 changes: 7 additions & 5 deletions apps/sim/background/workflow-column-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export async function executeWorkflowGroupCellJob(
signal?: AbortSignal
) {
const { tableId, rowId, workspaceId } = payload
const { getTableById, getRowById } = await import('@/lib/table/service')
const { getTableById } = await import('@/lib/table/service')
const { getRowById } = await import('@/lib/table/rows/service')
const { pickNextEligibleGroupForRow } = await import('@/lib/table/workflow-columns')

let currentPayload = payload
Expand Down Expand Up @@ -105,7 +106,8 @@ export async function runRowCascadeLoop(
signal?: AbortSignal
): Promise<'blocked' | undefined> {
const { tableId, rowId, workspaceId } = payload
const { getTableById, getRowById } = await import('@/lib/table/service')
const { getTableById } = await import('@/lib/table/service')
const { getRowById } = await import('@/lib/table/rows/service')
const { pickNextEligibleGroupForRow } = await import('@/lib/table/workflow-columns')

let currentGroupId = payload.groupId
Expand Down Expand Up @@ -175,7 +177,7 @@ async function runWorkflowAndWriteTerminal(
const requestId = `wfgrp-${executionId}`

return runWithRequestContext({ requestId }, async () => {
const { getRowById } = await import('@/lib/table/service')
const { getRowById } = await import('@/lib/table/rows/service')
const { executeWorkflow } = await import('@/lib/workflows/executor/execute-workflow')
const { loadWorkflowFromNormalizedTables, loadDeployedWorkflowState } = await import(
'@/lib/workflows/persistence/utils'
Expand Down Expand Up @@ -258,7 +260,7 @@ async function runWorkflowAndWriteTerminal(
logger.warn(
`Usage limit reached — halting enrichment (table=${tableId} row=${rowId} group=${groupId})`
)
const { updateRow } = await import('@/lib/table/service')
const { updateRow } = await import('@/lib/table/rows/service')
await updateRow(
{ tableId, rowId, data: {}, workspaceId, executionsPatch: { [groupId]: null } },
table,
Expand Down Expand Up @@ -525,7 +527,7 @@ async function runWorkflowAndWriteTerminal(
// cell's exec so it reverts to un-run (no error/cancelled badge —
// matching "don't mark"; re-runnable after upgrade). Each blocked
// cell clears its own.
const { updateRow } = await import('@/lib/table/service')
const { updateRow } = await import('@/lib/table/rows/service')
await updateRow(
{ tableId, rowId, data: {}, workspaceId, executionsPatch: { [groupId]: null } },
table,
Expand Down
3 changes: 3 additions & 0 deletions apps/sim/lib/copilot/request/tools/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const { mockGetTableById, mockReplaceTableRows } = vi.hoisted(() => ({

vi.mock('@/lib/table/service', () => ({
getTableById: mockGetTableById,
}))

vi.mock('@/lib/table/rows/service', () => ({
replaceTableRows: mockReplaceTableRows,
}))

Expand Down
3 changes: 2 additions & 1 deletion apps/sim/lib/copilot/request/tools/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { withCopilotSpan } from '@/lib/copilot/request/otel'
import type { ExecutionContext, ToolCallResult } from '@/lib/copilot/request/types'
import type { RowData, TableDefinition } from '@/lib/table'
import { buildIdByName, rowDataNameToId } from '@/lib/table/column-keys'
import { getTableById, replaceTableRows } from '@/lib/table/service'
import { replaceTableRows } from '@/lib/table/rows/service'
import { getTableById } from '@/lib/table/service'

const logger = createLogger('CopilotToolResultTables')

Expand Down
3 changes: 2 additions & 1 deletion apps/sim/lib/copilot/tools/handlers/function-execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { decodeVfsPathSegments, encodeVfsPathSegments } from '@/lib/copilot/vfs/
import { resolveWorkflowAliasForWorkspace } from '@/lib/copilot/vfs/workflow-alias-resolver'
import { isPlanAliasPath, workflowAliasSandboxPath } from '@/lib/copilot/vfs/workflow-aliases'
import { isMothershipBetaFeaturesEnabled } from '@/lib/core/config/feature-flags'
import { getTableById, listTables, queryRows } from '@/lib/table/service'
import { queryRows } from '@/lib/table/rows/service'
import { getTableById, listTables } from '@/lib/table/service'
import { listWorkspaceFileFolders } from '@/lib/uploads/contexts/workspace/workspace-file-folder-manager'
import {
fetchWorkspaceFileBuffer,
Expand Down
33 changes: 23 additions & 10 deletions apps/sim/lib/copilot/tools/server/table/user-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,39 @@ vi.mock('@/enrichments/registry', () => ({
}))

vi.mock('@/lib/table/service', () => ({
addTableColumn: vi.fn(),
addWorkflowGroup: mockAddWorkflowGroup,
batchInsertRows: mockBatchInsertRows,
batchUpdateRows: vi.fn(),
createTable: mockCreateTable,
deleteTable: mockDeleteTable,
getTableById: mockGetTableById,
renameTable: vi.fn(),
}))

vi.mock('@/lib/table/workflow-groups/service', () => ({
addWorkflowGroup: mockAddWorkflowGroup,
addWorkflowGroupOutput: vi.fn(),
deleteWorkflowGroup: vi.fn(),
deleteWorkflowGroupOutput: vi.fn(),
updateWorkflowGroup: vi.fn(),
}))

vi.mock('@/lib/table/columns/service', () => ({
addTableColumn: vi.fn(),
deleteColumn: vi.fn(),
deleteColumns: vi.fn(),
renameColumn: vi.fn(),
updateColumnConstraints: vi.fn(),
updateColumnType: vi.fn(),
}))

vi.mock('@/lib/table/rows/service', () => ({
batchInsertRows: mockBatchInsertRows,
batchUpdateRows: vi.fn(),
deleteRow: vi.fn(),
deleteRowsByFilter: vi.fn(),
deleteRowsByIds: vi.fn(),
deleteTable: mockDeleteTable,
getRowById: vi.fn(),
getTableById: mockGetTableById,
insertRow: vi.fn(),
queryRows: vi.fn(),
renameColumn: vi.fn(),
renameTable: vi.fn(),
replaceTableRows: mockReplaceTableRows,
updateColumnConstraints: vi.fn(),
updateColumnType: vi.fn(),
updateRow: vi.fn(),
updateRowsByFilter: vi.fn(),
}))
Expand Down
Loading
Loading