Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughRefactors API response handling to use centralized named types from a shared-schemas package, removes local helpers (str/extractArray), and updates data extraction and table field mappings across multiple CLI command handlers. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/commands/db/functions.ts (1)
19-22: Add runtime validation before accessingraw.functionsacross response extraction patterns.TypeScript's
asassertion provides compile-time type narrowing only; it performs no runtime validation. If the API response hasfunctionsas a non-array value (despite type expectations), the downstream.map()call will fail.This pattern appears consistently in four sibling command files (functions.ts, triggers.ts, policies.ts, indexes.ts). Each should guard the property access with
Array.isArray()before use.Proposed fix for functions.ts
const functions: DatabaseFunctionsResponse['functions'] = Array.isArray(raw) ? raw - : (raw as DatabaseFunctionsResponse).functions ?? []; + : Array.isArray((raw as DatabaseFunctionsResponse).functions) + ? (raw as DatabaseFunctionsResponse).functions + : [];Apply the same pattern to triggers.ts, policies.ts, and indexes.ts.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/db/functions.ts` around lines 19 - 22, The code uses a type assertion to treat `raw` as a `DatabaseFunctionsResponse` and then accesses `raw.functions` without runtime checks, which can crash if `functions` isn't an array; update the extraction in functions.ts to validate before use by replacing the current expression with a runtime-safe check that sets `functions` to `Array.isArray(raw) ? raw : Array.isArray((raw as DatabaseFunctionsResponse).functions) ? (raw as DatabaseFunctionsResponse).functions : []`, and apply the same defensive pattern in the sibling files that extract `triggers`, `policies`, and `indexes` (triggers.ts, policies.ts, indexes.ts) so each uses `Array.isArray(...)` before mapping over the property.src/commands/functions/list.ts (1)
37-37: Optional: handle invalid timestamps gracefully in table output.At Line 37, malformed timestamps can render as
"Invalid Date". Consider validating parsed dates and falling back to'-'.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/functions/list.ts` at line 37, The table output currently formats createdAt with new Date(f.createdAt).toLocaleString() which can produce "Invalid Date" for malformed timestamps; update the formatting in the list command (where f.createdAt is used) to parse the date into a Date object, check validity (e.g. const d = new Date(f.createdAt); if (isNaN(d.getTime())) use '-' else d.toLocaleString()), and return '-' on invalid or missing timestamps so the table never shows "Invalid Date".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/functions/list.ts`:
- Around line 18-23: Guard against raw being null/undefined before accessing
.functions: in the block that sets functions from raw (where you currently use
Array.isArray(raw) ? raw : (raw as ListFunctionsResponse).functions ?? []),
change the fallback to first check raw is an object (e.g., raw != null and
typeof raw === 'object' or raw && 'functions' in raw) before reading (raw as
ListFunctionsResponse).functions, and otherwise return []; this prevents a
runtime crash when raw is null/undefined while preserving the existing behavior
for arrays and valid ListFunctionsResponse objects.
- Around line 24-26: The CLI currently calls outputJson(raw) which exposes the
backend's raw shape and can be either an array or object; change the json branch
that calls outputJson to always emit a stable object schema like { functions:
[...] } by normalizing raw into an array (e.g., if raw is an array use it
directly, otherwise extract the list field or wrap raw in a single-element
array) and then call outputJson({ functions: normalizedArray }); update the code
around the existing outputJson(raw) call and the json flag handling to use this
normalized payload.
---
Nitpick comments:
In `@src/commands/db/functions.ts`:
- Around line 19-22: The code uses a type assertion to treat `raw` as a
`DatabaseFunctionsResponse` and then accesses `raw.functions` without runtime
checks, which can crash if `functions` isn't an array; update the extraction in
functions.ts to validate before use by replacing the current expression with a
runtime-safe check that sets `functions` to `Array.isArray(raw) ? raw :
Array.isArray((raw as DatabaseFunctionsResponse).functions) ? (raw as
DatabaseFunctionsResponse).functions : []`, and apply the same defensive pattern
in the sibling files that extract `triggers`, `policies`, and `indexes`
(triggers.ts, policies.ts, indexes.ts) so each uses `Array.isArray(...)` before
mapping over the property.
In `@src/commands/functions/list.ts`:
- Line 37: The table output currently formats createdAt with new
Date(f.createdAt).toLocaleString() which can produce "Invalid Date" for
malformed timestamps; update the formatting in the list command (where
f.createdAt is used) to parse the date into a Date object, check validity (e.g.
const d = new Date(f.createdAt); if (isNaN(d.getTime())) use '-' else
d.toLocaleString()), and return '-' on invalid or missing timestamps so the
table never shows "Invalid Date".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dc86e781-b0b1-4285-9faf-ecd99c700663
📒 Files selected for processing (17)
src/commands/db/functions.tssrc/commands/db/indexes.tssrc/commands/db/policies.tssrc/commands/db/triggers.tssrc/commands/deployments/list.tssrc/commands/functions/list.tssrc/commands/login.tssrc/commands/schedules/create.tssrc/commands/schedules/get.tssrc/commands/schedules/logs.tssrc/commands/secrets/add.tssrc/commands/secrets/delete.tssrc/commands/secrets/get.tssrc/commands/secrets/list.tssrc/commands/secrets/update.tssrc/commands/storage/buckets.tssrc/types.ts
Summary by CodeRabbit
Refactor
New Features
Bug Fixes