Skip to content

blocknote schema and import/export validation#40

Merged
ntietje1 merged 5 commits intomainfrom
dev
Apr 12, 2026
Merged

blocknote schema and import/export validation#40
ntietje1 merged 5 commits intomainfrom
dev

Conversation

@ntietje1
Copy link
Copy Markdown
Owner

@ntietje1 ntietje1 commented Apr 12, 2026

Summary by CodeRabbit

  • New Features

    • Block validation system with comprehensive schema and tighter runtime checks.
    • Improved text/markdown import and conversion (better parsing, link/image handling).
    • Headless editor utilities for reliable block↔Yjs conversions and streamlined note persistence.
    • Recursive folder-download collection.
  • Tests

    • Large test additions covering validation, text import/export, Yjs sync, folder downloads, and editor conversions.
  • Chores

    • Added Zod for schema validation.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 12, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wizard-archive 456dae4 Commit Preview URL

Branch Preview URL
Apr 12 2026, 07:09 PM

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

Warning

Rate limit exceeded

@ntietje1 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 11 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f2e2b4cb-9bee-4260-b3ee-d17176672358

📥 Commits

Reviewing files that changed from the base of the PR and between b813cc5 and 456dae4.

📒 Files selected for processing (1)
  • convex/blocks/blockNoteValidator.ts
📝 Walkthrough

Walkthrough

This PR adds Zod-based BlockNote schema validation, extracts BlockNote↔Yjs conversion utilities, tightens block/note types and validators, standardizes test factories, enhances text-to-block conversion, and introduces extensive tests for blocks, folder downloads, and editor text parsing.

Changes

Cohort / File(s) Summary
Test factories & test updates
convex/_test/factories.helper.ts, convex/blockShares/__tests__/blockShares.test.ts, convex/blockShares/__tests__/blockSharingWorkflows.test.ts, convex/notes/__tests__/noteWorkflows.test.ts, convex/yjsSync/__tests__/makeYjsUpdate.helper.ts
Added testBlock(id, overrides?) producing CustomBlock; updated tests to use it; adjusted test helper types and signatures to consume TestBlock/CustomBlock shapes.
BlockNote schema & validators
convex/blocks/blockNoteValidator.ts, convex/blocks/__tests__/blockNoteValidator.test.ts, package.json
Introduced Zod recursive blockNoteBlockSchema and exported Convex validator; added zod dependency; added tests validating BlockNote block shapes and styles.
Block/Note schema & types tightening
convex/blocks/schema.ts, convex/blocks/types.ts, convex/blockShares/types.ts, convex/notes/schema.ts, src/features/sidebar/hooks/useCreateSidebarItem.ts
Replaced loose validators/types with typed blockNoteBlockValidator/customBlockValidator; changed Block type to Doc<'blocks'>; tightened noteWithContentValidator and CreateNoteArgs to use CustomBlock.
Yjs / BlockNote conversion utilities
convex/notes/blocknote.ts, convex/notes/functions/createNote.ts, convex/notes/mutations.ts
Extracted blocksToYDoc and yDocToBlocks utilities; refactored create/persist flows to call these utilities instead of instantiating headless editors; simplified resource cleanup.
Text → Blocks conversion
src/features/editor/utils/text-to-blocks.ts, src/features/editor/utils/__tests__/text-to-blocks.test.ts
Added isMarkdownFile and convertTextContentToBlocks, changed convertTextToBlocks to return CustomBlock[], flattened link/image nodes into markdown-style inline text, normalized newlines, and added comprehensive tests (large test coverage).
Folder/download & file utilities tests
convex/folders/__tests__/getFolderContentsForDownload.test.ts, src/features/file-upload/utils/__tests__/folder-reader.test.ts
Added exhaustive tests for recursive folder/item collection, download naming/path rules, file/folder counting utilities, and handling of mixed item types.
Snapshots / Yjs test minor changes
convex/documentSnapshots/__tests__/rollbackEdgeCases.test.ts, convex/documentSnapshots/__tests__/snapshot.test.ts
Removed as const literal assertions from test block objects to simplify types without changing test logic.
Misc (imports/reordering)
convex/blockShares/types.ts, README.md
Minor import reorder; documented Zod in README and updated tech/test coverage badges/text.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Testing #26: Directly related — touches and extends the same convex/_test/factories.helper.ts test factory infrastructure.
  • Note yjs #30: Overlaps BlockNote↔Yjs conversion changes and createNote/persistence surface.
  • add canvases #33: Related through shared changes to BlockNote/Yjs conversion and yjsSync test helpers.

Poem

🐰
A carrot-coded block I bring,
Validators tidy every string,
Text turns markdown, Yjs will flow,
Tests hop in row by row,
Happy hops — the repo grows!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'blocknote schema and import/export validation' directly and accurately summarizes the main changes: introducing BlockNote schema validation via Zod, refactoring to use that schema throughout, and adding import/export utilities with comprehensive test coverage.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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.

❤️ Share

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

@github-actions
Copy link
Copy Markdown

Preview Deployment

Service URL
Frontend https://preview-40.wizardarchive.com

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@convex/blocks/blockNoteValidator.ts`:
- Around line 6-219: Replace permissive z.object(...) schemas with
z.strictObject(...) for all document shapes so unknown keys are rejected: update
stylesSchema, styledTextSchema, inlineContentSchema, tableContentSchema,
defaultPropsSchema entries, and every block object inside the z.lazy
discriminated union (the blockNoteBlockSchema cases such as 'paragraph',
'heading', 'bulletListItem', 'numberedListItem', 'checkListItem',
'toggleListItem', 'quote', 'codeBlock', 'divider', 'image', 'video', 'audio',
'file', and 'table') so that both the outer block objects and their nested props
objects use z.strictObject(...) (and mark optional schemas the same way) to
enforce strict validation and prevent unknown fields from being accepted.

In `@src/features/file-upload/utils/__tests__/folder-reader.test.ts`:
- Around line 13-17: The test fixtures duplicate file creation between makeFile
and makeFolder; change makeFolder to reuse makeFile instead of reimplementing
the File/relativePath construction so path behavior is centralized—have
makeFolder call makeFile for each file entry (or accept File objects created by
makeFile) and build the folder's entries from those returned fixtures, then
remove the duplicated logic in makeFolder and update any tests that previously
constructed files directly to use makeFile (also adjust the other duplicated
occurrences where files are created to call makeFile).
🪄 Autofix (Beta)

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: ASSERTIVE

Plan: Pro

Run ID: be672c6b-6ca4-4756-b136-69ad6b7deeee

📥 Commits

Reviewing files that changed from the base of the PR and between ece3d0d and 88375f1.

⛔ Files ignored due to path filters (2)
  • convex/_generated/api.d.ts is excluded by !**/_generated/**
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (22)
  • convex/_test/factories.helper.ts
  • convex/blockShares/__tests__/blockShares.test.ts
  • convex/blockShares/__tests__/blockSharingWorkflows.test.ts
  • convex/blockShares/types.ts
  • convex/blocks/__tests__/blockNoteValidator.test.ts
  • convex/blocks/blockNoteValidator.ts
  • convex/blocks/schema.ts
  • convex/blocks/types.ts
  • convex/documentSnapshots/__tests__/rollbackEdgeCases.test.ts
  • convex/documentSnapshots/__tests__/snapshot.test.ts
  • convex/folders/__tests__/getFolderContentsForDownload.test.ts
  • convex/notes/__tests__/noteWorkflows.test.ts
  • convex/notes/blocknote.ts
  • convex/notes/functions/createNote.ts
  • convex/notes/mutations.ts
  • convex/notes/schema.ts
  • convex/yjsSync/__tests__/makeYjsUpdate.helper.ts
  • package.json
  • src/features/editor/utils/__tests__/text-to-blocks.test.ts
  • src/features/editor/utils/text-to-blocks.ts
  • src/features/file-upload/utils/__tests__/folder-reader.test.ts
  • src/features/sidebar/hooks/useCreateSidebarItem.ts
👮 Files not reviewed due to content moderation or server errors (8)
  • package.json
  • convex/notes/blocknote.ts
  • convex/yjsSync/tests/makeYjsUpdate.helper.ts
  • src/features/editor/utils/text-to-blocks.ts
  • src/features/editor/utils/tests/text-to-blocks.test.ts
  • convex/documentSnapshots/tests/snapshot.test.ts
  • convex/notes/tests/noteWorkflows.test.ts
  • convex/blockShares/tests/blockShares.test.ts

Comment thread convex/blocks/blockNoteValidator.ts
Comment on lines +13 to +17
function makeFile(name: string): { file: File; relativePath: string } {
return {
file: new File([''], name),
relativePath: name,
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Deduplicate file fixture creation in helpers.

makeFolder reimplements makeFile logic. Reusing one helper reduces fixture drift and keeps path behavior centralized.

♻️ Suggested refactor
-function makeFile(name: string): { file: File; relativePath: string } {
+function makeFile(name: string, relativePath: string = name): { file: File; relativePath: string } {
   return {
     file: new File([''], name),
-    relativePath: name,
+    relativePath,
   }
 }
@@
     relativePath: name,
-    files: files.map((f) => ({
-      file: new File([''], f),
-      relativePath: `${name}/${f}`,
-    })),
+    files: files.map((f) => makeFile(f, `${name}/${f}`)),
     subfolders,
   }
 }

Also applies to: 28-31

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/features/file-upload/utils/__tests__/folder-reader.test.ts` around lines
13 - 17, The test fixtures duplicate file creation between makeFile and
makeFolder; change makeFolder to reuse makeFile instead of reimplementing the
File/relativePath construction so path behavior is centralized—have makeFolder
call makeFile for each file entry (or accept File objects created by makeFile)
and build the folder's entries from those returned fixtures, then remove the
duplicated logic in makeFolder and update any tests that previously constructed
files directly to use makeFile (also adjust the other duplicated occurrences
where files are created to call makeFile).

@ntietje1 ntietje1 merged commit 65c62a0 into main Apr 12, 2026
15 checks passed
@ntietje1 ntietje1 deleted the dev branch April 12, 2026 19:11
This was referenced Apr 13, 2026
Merged
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