Skip to content

Commit 9993fc2

Browse files
committed
chore(cleanup): use isRecordLike for inline record guards
1 parent 6594698 commit 9993fc2

13 files changed

Lines changed: 32 additions & 28 deletions

‎apps/sim/lib/knowledge/documents/processing-outbox-handler.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
import { assertBillingAttributionSnapshot } from '@/lib/billing/core/billing-attribution'
23
import { env, envNumber } from '@/lib/core/config/env'
34
import { isTriggerAvailable } from '@/lib/core/config/trigger-availability'
@@ -67,7 +68,7 @@ import {
6768
} from '@/lib/knowledge/documents/storage-cleanup'
6869

6970
function requirePayloadRecord(payload: unknown): Record<string, unknown> {
70-
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
71+
if (!isRecordLike(payload)) {
7172
throw new Error('Knowledge document processing outbox payload must be an object')
7273
}
7374
return payload as Record<string, unknown>

‎apps/sim/lib/knowledge/secret-provenance-selection.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
export interface KnowledgeDocumentTagProvenanceTarget {
23
tagName: string
34
value: unknown
@@ -16,7 +17,7 @@ export function parseKnowledgeDocumentTagProvenanceTargets(
1617
const parsed: unknown = JSON.parse(documentTagsData)
1718
if (!Array.isArray(parsed)) return []
1819
return parsed.flatMap((candidate) => {
19-
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) return []
20+
if (!isRecordLike(candidate)) return []
2021
const record = candidate as Record<string, unknown>
2122
const tagName = typeof record.tagName === 'string' ? record.tagName.trim() : ''
2223
if (!tagName || record.value === undefined || record.value === null || record.value === '') {

‎apps/sim/lib/table/columns/workflow-references.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
/**
23
* Finds workflow Table blocks whose saved configuration still names a column by
34
* its old name after a rename.
@@ -39,13 +40,9 @@ const TABLE_ID_SUB_BLOCKS = ['manualTableId', 'tableSelector', 'tableId'] as con
3940

4041
const TABLE_BLOCK_TYPE = 'table_v2'
4142

42-
function isRecord(value: unknown): value is Record<string, unknown> {
43-
return typeof value === 'object' && value !== null && !Array.isArray(value)
44-
}
45-
4643
function subBlockValue(subBlocks: SubBlockValues, id: string): unknown {
4744
const entry = subBlocks[id]
48-
return isRecord(entry) ? entry.value : undefined
45+
return isRecordLike(entry) ? entry.value : undefined
4946
}
5047

5148
/** The raw text of a sub-block, or `undefined` when it holds nothing. */
@@ -70,7 +67,7 @@ export function isTableBlockBoundTo(subBlocks: SubBlockValues, tableId: string):
7067

7168
/** Every column a row payload names: the keys of the `{ column: value }` object. */
7269
function collectDataFieldNames(root: unknown): string[] {
73-
return isRecord(root) ? Object.keys(root) : []
70+
return isRecordLike(root) ? Object.keys(root) : []
7471
}
7572

7673
const FIELD_COLLECTORS: Record<TableBlockColumnReferenceField, (root: unknown) => string[]> = {
@@ -147,7 +144,7 @@ export async function findUnmigratedTableBlockReferences(input: {
147144

148145
const unmigrated: UnmigratedTableBlockReference[] = []
149146
for (const row of rows) {
150-
if (!isRecord(row.subBlocks)) continue
147+
if (!isRecordLike(row.subBlocks)) continue
151148
const subBlocks = row.subBlocks as SubBlockValues
152149
if (!isTableBlockBoundTo(subBlocks, input.tableId)) continue
153150
const fields = collectTableBlockColumnReferences(subBlocks, input.columnName)

‎apps/sim/lib/table/import.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
/**
23
* Shared CSV import helpers for user-defined tables.
34
*
@@ -760,7 +761,7 @@ export function parseJsonRows(buffer: Buffer | string): {
760761
}
761762
const headerSet = new Set<string>()
762763
for (const row of parsed) {
763-
if (typeof row !== 'object' || row === null || Array.isArray(row)) {
764+
if (!isRecordLike(row)) {
764765
throw new OrchestrationError(
765766
'validation',
766767
'Each element in the JSON array must be a plain object'

‎apps/sim/lib/table/orchestration/import-resource.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { tableJobs } from '@sim/db/schema'
44
import { createLogger } from '@sim/logger'
55
import { getErrorMessage } from '@sim/utils/errors'
66
import { generateId } from '@sim/utils/id'
7+
import { isRecordLike } from '@sim/utils/object'
78
import { and, eq } from 'drizzle-orm'
89
import {
910
type V2CreateTableImportBody,
@@ -527,7 +528,7 @@ function parseRejectionSummary(payload: unknown): TableImportRejectionSummary {
527528
cellsRejected: 0,
528529
rejectedSamples: [],
529530
}
530-
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return empty
531+
if (!isRecordLike(payload)) return empty
531532
const candidate = payload as Partial<TableImportRejectionSummary>
532533
const samples = Array.isArray(candidate.rejectedSamples) ? candidate.rejectedSamples : []
533534
return {
@@ -548,7 +549,7 @@ function parseRejectionSummary(payload: unknown): TableImportRejectionSummary {
548549
* handed unchanged to a `.strict()` schema and turn a read of the import into a 500.
549550
*/
550551
function parseRejectedSample(value: unknown): CsvSkippedRecord | null {
551-
if (!value || typeof value !== 'object' || Array.isArray(value)) return null
552+
if (!isRecordLike(value)) return null
552553
const candidate = value as Partial<CsvSkippedRecord>
553554
if (typeof candidate.code !== 'string' || typeof candidate.message !== 'string') return null
554555
const line =
@@ -570,7 +571,7 @@ function parseRejectionCount(value: unknown): number {
570571
* an ordinary "not this resource" answer rather than an error condition.
571572
*/
572573
function parseImportJobPayload(payload: unknown): ParsedTableImportPayload | null {
573-
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return null
574+
if (!isRecordLike(payload)) return null
574575
const candidate = payload as Partial<TableImportJobPayload>
575576
if (
576577
candidate.kind !== 'table_import' ||

‎apps/sim/lib/table/query-builder/converters.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ function parseScalar(value: string): JsonValue {
251251
}
252252

253253
function parseFilterGroup(group: Filter): FilterRule[] {
254-
if (!group || typeof group !== 'object' || Array.isArray(group)) return []
254+
if (!isRecordLike(group)) return []
255255

256256
const rules: FilterRule[] = []
257257

‎apps/sim/lib/table/query-builder/field-names.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
/**
23
* Column names an authored filter or sort names, read from untrusted JSON.
34
*
@@ -8,10 +9,6 @@
89
* these are advisory readers of persisted block state.
910
*/
1011

11-
function isRecord(value: unknown): value is Record<string, unknown> {
12-
return typeof value === 'object' && value !== null && !Array.isArray(value)
13-
}
14-
1512
/**
1613
* Every `field` a predicate tree names, in document order: a bare
1714
* `{ field, op, value }` condition, or nested `{ all | any: [...] }` groups.
@@ -29,7 +26,7 @@ export function collectPredicateFieldNames(root: unknown): string[] {
2926
visitLater(node)
3027
continue
3128
}
32-
if (!isRecord(node)) continue
29+
if (!isRecordLike(node)) continue
3330
if (typeof node.field === 'string') names.push(node.field)
3431
if (Array.isArray(node.any)) visitLater(node.any)
3532
if (Array.isArray(node.all)) visitLater(node.all)
@@ -44,8 +41,8 @@ export function collectPredicateFieldNames(root: unknown): string[] {
4441
export function collectSortFieldNames(root: unknown): string[] {
4542
if (Array.isArray(root)) {
4643
return root.flatMap((entry) =>
47-
isRecord(entry) && typeof entry.field === 'string' ? [entry.field] : []
44+
isRecordLike(entry) && typeof entry.field === 'string' ? [entry.field] : []
4845
)
4946
}
50-
return isRecord(root) ? Object.keys(root) : []
47+
return isRecordLike(root) ? Object.keys(root) : []
5148
}

‎apps/sim/lib/table/rows/cursor.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
/**
23
* Opaque pagination cursor for the v2 table-query surface.
34
*
@@ -235,7 +236,7 @@ export function decodeCursor(token: string): {
235236
} catch {
236237
invalidCursor()
237238
}
238-
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) {
239+
if (!isRecordLike(payload)) {
239240
invalidCursor()
240241
}
241242

‎apps/sim/lib/table/rows/run-state.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecordLike } from '@sim/utils/object'
12
/**
23
* Shared normalizers for the `tableRowExecutions` sidecar columns that are
34
* stored looser than every consumer declares them.
@@ -17,7 +18,7 @@
1718
* rather than publish an empty map.
1819
*/
1920
export function normalizeBlockErrors(value: unknown): Record<string, string> | undefined {
20-
if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined
21+
if (!isRecordLike(value)) return undefined
2122

2223
const blockErrors: Record<string, string> = {}
2324
for (const [blockId, error] of Object.entries(value)) {

‎apps/sim/lib/table/rows/secret-provenance.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
userTableRows,
77
} from '@sim/db/schema'
88
import { createLogger } from '@sim/logger'
9+
import { isRecordLike } from '@sim/utils/object'
910
import { compareStrings } from '@sim/utils/string'
1011
import { and, asc, eq, gt, inArray, type SQL, sql } from 'drizzle-orm'
1112
import { SecretProvenanceBudget } from '@/lib/execution/provenance-budget'
@@ -127,7 +128,7 @@ function serializedBytes(value: unknown): number {
127128
}
128129

129130
function isStoredEntry(value: unknown): value is StoredTableRowSecretProvenanceEntry {
130-
if (!value || typeof value !== 'object' || Array.isArray(value)) return false
131+
if (!isRecordLike(value)) return false
131132
const record = value as Record<string, unknown>
132133
if (
133134
Reflect.ownKeys(record).some((key) => typeof key !== 'string' || !STORED_ENTRY_KEYS.has(key))

0 commit comments

Comments
 (0)