Repository navigation
feat: notebook content schema - #48813
Conversation
Introduce Zod schemas for notebook content type, the first in a series of PRs implementing Notebooks — a new SQL Editor content combining SQL, markdown, and log cells. Key additions: - notebook-schema.ts: Zod schemas mirroring RFC-defined shape (schema_version, cells discriminated by _tag). Maintains separation between wire schema (id required, plain sql) and domain schema (id required, sql branded as unchecked_sql for security). Agent-writable schema for create operations omits ids (backend-generated); update operations (later PR) will require them. - iso-datetime.ts: Moved IsoDateTimeString/validator from querySource.ts to lib layer (data/ shouldn't import from components/). Needed by notebook time_range fields. querySource imports updated. - content-query.ts: Workaround for unpublished platform API notebook type — locally widened ContentBase type to include 'notebook' (TODO for removal when api:codegen catches up; does not touch generated packages/api-types). - types/userContent.ts: Notebooks namespace re-exporting Zod-inferred types. All types are z.infer'd from schemas (no hand-written parallel interfaces), ensuring runtime validation and compile-time types can't drift.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughAdds shared ISO datetime validation and introduces Zod schemas for wire, agent, and domain notebook data. Exports notebook types, supports notebook content, transforms SQL into branded values, and adds comprehensive validation tests. ChangesNotebook schema foundation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant NotebookInput
participant notebookDomainSchema
participant untrustedSql
participant untrustedLogSql
NotebookInput->>notebookDomainSchema: Parse notebook wire data
notebookDomainSchema->>untrustedSql: Transform database SQL
notebookDomainSchema->>untrustedLogSql: Transform log SQL
notebookDomainSchema-->>NotebookInput: Return domain notebook
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/data/content/content-query.ts`:
- Around line 9-14: Extend the Content domain union to include a parsed notebook
variant using notebookDomainSchema, and update remapSqlContentFields to
transform notebook cell.sql values into branded unchecked_sql values where
required. Ensure getContent returns the notebook variant and add coverage for
notebook parsing and remapping.
In `@apps/studio/lib/iso-datetime.ts`:
- Around line 16-18: Update isoDateTimeString to use the existing strict Zod ISO
datetime validation path from notebook-schema.ts instead of
dayjs(raw).isValid(). Return null for malformed or overflow values, and brand
only the validated result without using a direct `as` cast.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ec58f30f-9db2-435c-ac93-047207644690
📒 Files selected for processing (8)
apps/studio/components/interfaces/SQLEditor/querySource.test.tsapps/studio/components/interfaces/SQLEditor/querySource.tsapps/studio/data/content/content-query.tsapps/studio/data/content/notebooks/notebook-schema.test.tsapps/studio/data/content/notebooks/notebook-schema.tsapps/studio/lib/iso-datetime.test.tsapps/studio/lib/iso-datetime.tsapps/studio/types/userContent.ts
joshenlim
left a comment
There was a problem hiding this comment.
Yup all LGTM as per what we chatted! 🙏 🙂
🎭 Playwright Test Results (tanstack)Details
Flaky testsFeatures › column-editor-types.spec.ts › column editor complex types › FK selector allows and creates a relation between two matching array columns Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
Braintrust eval report
|
…for-pitr-archiving-stale * origin/master: (342 commits) feat(studio): role-aware access feedback in scoped token creation (#48858) Initialize notebook editor page (#48842) test(docs): scan changed pages for WCAG 2.1 A/AA in warn mode (#48727) docs(auth): clarify audit logs storage options and configuration (#48852) feat(studio): warn that scoped tokens don't support the MCP server (#48849) feat(studio): lifecycle and role-aware scoped token view sheet (#48848) feat(www): add Open Authorization Integration Addendum (#48804) feat(studio): add legacy token mode to scoped pat creation flow (#48844) Add blog post: Supabase is now a connector on Perplexity Computer (#48776) feat(studio): enforce expiry scoped pat (#48811) fix(studio): model scoped pat permissions as OR-of-AND alternatives - smaller version (#48809) fix(ui): opaque default button hover fills (#48837) fix(ui): restore normal alert text wrapping (#48840) feat: notebook content schema (#48813) fix(ui): remove extra spacing before custom reports section (#48796) feat(marketing): add hint text below Go page form labels (#48824) Initialize notebooks store (#48801) Use white wordmark for QA.tech primary logo (#48827) fix titleless Admonition alignment (#48784) fix inconsistent product menu dividers (#48787) ...
## Summary Stacked on #48813 (1.2: notebook content schema). Part of [FE-4109](https://linear.app/supabase/issue/FE-4109/notebooks-data-model) — see that issue for the rest of the notebooks data-model stack. - Teach `content-remap.ts`'s wire↔domain dispatcher about the `notebook` content type, branding each cell's `sql` per `_tag` via the notebook schemas added in 1.2 (parses through `notebookDomainSchema` on the way in, unbrands per cell on the way out). - Add `{ type: 'notebook'; content: Notebooks.Content }` to the `Content` union in `content-query.ts`, plus a `ContentOfType<T>` helper for narrowing it. - Fix the resulting narrowing fallout at call sites that assumed `Content` only ever meant `sql`/`report`/`log_sql`: two generated-query-param casts, and four report/logs call sites now narrowed via `ContentOfType<'report'>` / `ContentOfType<'log_sql'>`. ## Test plan - [x] `pnpm --filter studio vitest run data/content/` — 35 tests pass, including new notebook coverage in `content-remap.test.ts` (per-cell brand separation, missing-field throw, remap↔unmap round-trip) - [x] `pnpm typecheck` — clean (pre-existing unrelated `ui-patterns` error aside) - [x] `pnpm --filter studio lint` — no new warnings/errors on changed files - [x] `pnpm format` — clean --------- Co-authored-by: Joshen Lim <[email protected]>
…#48905) ## Summary - Joshen's `state/notebooks/types.ts` (Explorer/notebook editor UI) redefined its own `TimeRange`, cell union, and `NotebookContent` shapes, duplicating the canonical schema from `data/content/notebooks/notebook-schema.ts` (#48813, #48815). - Points `Notebook.content` and `notebooksState.updateCells` at the canonical `Notebooks.Content` / `Notebooks.Cell` types (via `@/types`) instead, and fixes the handful of call sites that constructed notebook content by hand to match the real wire shape: `schema_version: 1` (not `'1.0'`) and `_tag`-discriminated cells (e.g. `{ _tag: 'markdown_cell', id, text }` instead of `{ type: 'markdown', content }`). - No behavioral changes — Joshen's state management, editor component, and hooks are untouched aside from the type-level fixes needed to compile against the canonical schema. ## Test plan - [x] `pnpm exec tsc --noEmit` — no new errors - [x] `pnpm exec vitest run state/notebooks/notebooks-state.test.ts components/interfaces/Explorer/__tests__/NotebookEditor.test.tsx` — 8/8 passing - [x] `pnpm exec eslint` on changed files — clean - [x] `pnpm exec prettier --check` on changed files — clean <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Updated notebook content handling to use the current schema version format. * Improved compatibility for markdown cells, including their identifiers and text. * Standardized notebook content and cell updates for more consistent behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Related to FE-4109.
Summary
notebookcontent type hasn't shipped to the OpenAPI spec yet, sopnpm api:codegencan't be run. Locally widenedContentBase.typeto include'notebook'(marked with TODO for removal once spec publishes).schema_version: 1, cells: Cell[]). Maintains wire/domain boundary (cellsql→unchecked_sqlbranded for security). Agent-writable schema forcreate_notebooktool omits cell IDs (backend-generated); future update operations will require them. All TypeScript types arez.infer'd from schemas (no hand-written parallel interfaces).querySource.tstolib/iso-datetime.ts(data layer shouldn't import from components layer). Needed by notebooktime_rangefields.Test plan
notebook-schema.test.ts(9 tests),iso-datetime.test.ts(3 tests),querySource.test.tsupdated and passing (26 tests)Summary by CodeRabbit
New Features
Tests