Skip to content

Chore/data schema#10

Merged
jwfing merged 4 commits intomainfrom
chore/data-schema
Mar 4, 2026
Merged

Chore/data schema#10
jwfing merged 4 commits intomainfrom
chore/data-schema

Conversation

@jwfing
Copy link
Contributor

@jwfing jwfing commented Mar 4, 2026

Summary by CodeRabbit

  • Refactor

    • Improved type safety and unified API response handling across DB, deployments, functions, schedules, secrets, and storage commands for more consistent behavior.
  • New Features

    • Storage buckets now show Public/Private status in command output.
  • Bug Fixes

    • Database, indexes, policies, and triggers outputs updated with clearer field mappings and more reliable table rendering.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 073f0007-09e6-4b6d-8c8c-0b226a0c1325

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba7da5 and 4505702.

📒 Files selected for processing (3)
  • src/commands/deployments/list.ts
  • src/commands/functions/list.ts
  • src/commands/storage/buckets.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/commands/deployments/list.ts
  • src/commands/functions/list.ts

Walkthrough

Refactors 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

Cohort / File(s) Summary
Type System Consolidation
src/types.ts
Removes local OSS type interfaces and re-exports multiple response types from a shared-schemas package, centralizing type definitions.
Database Commands
src/commands/db/functions.ts, src/commands/db/indexes.ts, src/commands/db/policies.ts, src/commands/db/triggers.ts
Drops local helpers, imports Database*Response types, normalizes raw JSON to typed arrays (e.g., raw or raw.functions), and updates table columns/field mappings (e.g., Name → Definition/Kind changes).
Deployments & Functions List
src/commands/deployments/list.ts, src/commands/functions/list.ts
Adds typed response imports (ListDeploymentsResponse, ListFunctionsResponse), derives arrays from raw or raw.data/raw.functions, and adjusts displayed fields (e.g., created_at → createdAt, URL fallback simplified).
Secrets Commands
src/commands/secrets/add.ts, src/commands/secrets/delete.ts, src/commands/secrets/get.ts, src/commands/secrets/list.ts, src/commands/secrets/update.ts
Replaces inline response shapes with named types (Create/Delete/Get/List/Update Secret responses); minor adjustments to variable usage and JSON vs table output selection.
Schedules Commands
src/commands/schedules/create.ts, src/commands/schedules/get.ts, src/commands/schedules/logs.ts
Uses named schedule/log response types (CreateScheduleResponse, GetScheduleResponse, ListExecutionLogsResponse) instead of generic casts; runtime behavior unchanged.
Storage Buckets
src/commands/storage/buckets.ts
Imports StorageBucketSchema, normalizes buckets to StorageBucketSchema[], changes table columns to include Public and maps rows to [b.name, b.public ? 'Yes' : 'No'].
Login Command
src/commands/login.ts
Removes an unused import (getPlatformApiUrl) from config; no behavior change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped through types and cleaned the trail,
Swapped scattered nests for one shared grail,
Fields aligned and helpers gone,
Tables tidy at the dawn,
A happy rabbit, code trimmed hale.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Chore/data schema' is vague and uses non-descriptive formatting that doesn't clearly convey the scope of changes, which involve refactoring type definitions and updating API response handling across multiple command files. Revise the title to be more specific and descriptive, such as 'Refactor API response types and move type definitions to shared-schemas' or 'Update response handling with explicit types from shared-schemas'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/data-schema

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/commands/db/functions.ts (1)

19-22: Add runtime validation before accessing raw.functions across response extraction patterns.

TypeScript's as assertion provides compile-time type narrowing only; it performs no runtime validation. If the API response has functions as 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc1551 and 4ba7da5.

📒 Files selected for processing (17)
  • src/commands/db/functions.ts
  • src/commands/db/indexes.ts
  • src/commands/db/policies.ts
  • src/commands/db/triggers.ts
  • src/commands/deployments/list.ts
  • src/commands/functions/list.ts
  • src/commands/login.ts
  • src/commands/schedules/create.ts
  • src/commands/schedules/get.ts
  • src/commands/schedules/logs.ts
  • src/commands/secrets/add.ts
  • src/commands/secrets/delete.ts
  • src/commands/secrets/get.ts
  • src/commands/secrets/list.ts
  • src/commands/secrets/update.ts
  • src/commands/storage/buckets.ts
  • src/types.ts

@jwfing jwfing merged commit 8bf9939 into main Mar 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant