feat: Add support for Parse.File.setDirectory, setMetadata, setTags with stream-based file upload#10092
Conversation
|
🚀 Thanks for opening this pull request! |
📝 WalkthroughWalkthroughUpdates the "parse" dependency to 8.4.0, adds header-driven extraction of directory/metadata/tags for streaming uploads in FilesRouter, and introduces extensive tests covering streaming upload behaviors and validations. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.41.0)spec/ParseFile.spec.jsThanks 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 |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
package.json (1)
51-51: Optional: use a changelog-friendly PR title.Suggested title:
feat(files): support stream upload headers for directory, metadata, and tagsBased on learnings: For Parse Server PRs, always suggest an Angular commit convention PR title in
type(scope): descriptionformat.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@package.json` at line 51, Update the pull request title to follow the Angular commit convention (type(scope): description) so it is changelog-friendly; for this change use the suggested title "feat(files): support stream upload headers for directory, metadata, and tags" when opening or updating the PR — this is related to the package.json change around the "parse" dependency and will ensure the PR appears correctly in release notes.src/Routers/FilesRouter.js (1)
317-339: Document the new streaming headers in public docs.Please add README/REST docs for
X-Parse-File-Directory,X-Parse-File-Metadata, andX-Parse-File-Tags(including master-key requirement for directory and JSON-object constraints).Based on learnings: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in README.md, though for new options this is optional.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Routers/FilesRouter.js` around lines 317 - 339, Add documentation for the new streaming upload headers referenced in FilesRouter.js: X-Parse-File-Directory, X-Parse-File-Metadata, and X-Parse-File-Tags. Update the public README/REST docs to describe each header, note that X-Parse-File-Directory requires master key authorization, and state that X-Parse-File-Metadata and X-Parse-File-Tags must be valid JSON objects (include examples of valid JSON and an example request showing the X-Parse-Upload-Mode: stream flow). Also mention the behavior in FilesRouter where these headers are parsed into req.fileData.directory, req.fileData.metadata, and req.fileData.tags and how invalid JSON results in a Parse.Error.INVALID_JSON response.spec/ParseFile.spec.js (1)
2424-2464: Add tests for valid-JSON-but-invalid-shape headers.You currently cover malformed JSON only. Please add cases like
null,[], and"text"for metadata/tags headers to lock in object-only validation behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@spec/ParseFile.spec.js` around lines 2424 - 2464, Add tests that assert headers containing valid JSON but wrong shapes (e.g., "null", "[]", and "\"text\"") for both X-Parse-File-Metadata and X-Parse-File-Tags are rejected with Parse.Error.INVALID_JSON; update or add new it blocks (similar to the existing "rejects invalid JSON in metadata header" and "rejects invalid JSON in tags header") to call request(...) with those header values and expect the thrown error.data.code to equal Parse.Error.INVALID_JSON, or alternatively factor into a small loop inside each existing spec that iterates the invalid-shape payloads and asserts the same failure using the request helper.
🤖 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/Routers/FilesRouter.js`:
- Around line 323-337: The parsing for X-Parse-File-Metadata and
X-Parse-File-Tags in FilesRouter.js currently accepts any JSON (null, arrays,
strings); after JSON.parse in the req handling block that sets
req.fileData.metadata and req.fileData.tags, validate that the parsed value is a
non-null plain object (e.g., typeof value === 'object' && value !== null &&
!Array.isArray(value')); if the check fails call next(new
Parse.Error(Parse.Error.INVALID_JSON, 'Invalid JSON in X-Parse-File-Metadata
header. Must be a JSON object.')) (and analogous message for X-Parse-File-Tags)
and return; update the logic around the metadata/tags assignment in the same
try/catch blocks that handle JSON.parse to enforce object-only inputs and
prevent downstream Object.keys(...) errors.
---
Nitpick comments:
In `@package.json`:
- Line 51: Update the pull request title to follow the Angular commit convention
(type(scope): description) so it is changelog-friendly; for this change use the
suggested title "feat(files): support stream upload headers for directory,
metadata, and tags" when opening or updating the PR — this is related to the
package.json change around the "parse" dependency and will ensure the PR appears
correctly in release notes.
In `@spec/ParseFile.spec.js`:
- Around line 2424-2464: Add tests that assert headers containing valid JSON but
wrong shapes (e.g., "null", "[]", and "\"text\"") for both X-Parse-File-Metadata
and X-Parse-File-Tags are rejected with Parse.Error.INVALID_JSON; update or add
new it blocks (similar to the existing "rejects invalid JSON in metadata header"
and "rejects invalid JSON in tags header") to call request(...) with those
header values and expect the thrown error.data.code to equal
Parse.Error.INVALID_JSON, or alternatively factor into a small loop inside each
existing spec that iterates the invalid-shape payloads and asserts the same
failure using the request helper.
In `@src/Routers/FilesRouter.js`:
- Around line 317-339: Add documentation for the new streaming upload headers
referenced in FilesRouter.js: X-Parse-File-Directory, X-Parse-File-Metadata, and
X-Parse-File-Tags. Update the public README/REST docs to describe each header,
note that X-Parse-File-Directory requires master key authorization, and state
that X-Parse-File-Metadata and X-Parse-File-Tags must be valid JSON objects
(include examples of valid JSON and an example request showing the
X-Parse-Upload-Mode: stream flow). Also mention the behavior in FilesRouter
where these headers are parsed into req.fileData.directory,
req.fileData.metadata, and req.fileData.tags and how invalid JSON results in a
Parse.Error.INVALID_JSON response.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 326151de-2200-4b94-9dab-d0adeff43f30
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
package.jsonspec/ParseFile.spec.jssrc/Routers/FilesRouter.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
spec/ParseFile.spec.js (1)
2375-2397: Use non-master auth in metadata/tags-only success test to avoid over-privileged coverage.This test doesn’t set directory, so using
X-Parse-Master-Keycan hide regressions for regular clients. Prefer REST/API-key auth here.♻️ Suggested test tweak
const headers = { 'Content-Type': 'text/plain', 'X-Parse-Application-Id': 'test', - 'X-Parse-Master-Key': 'test', + 'X-Parse-REST-API-Key': 'rest', 'X-Parse-Upload-Mode': 'stream', 'X-Parse-File-Metadata': JSON.stringify({ key1: 'value1' }), 'X-Parse-File-Tags': JSON.stringify({ tag1: 'tagValue1' }), };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@spec/ParseFile.spec.js` around lines 2375 - 2397, The test "saves file with metadata and tags via streaming upload headers" uses X-Parse-Master-Key which grants master privileges; replace that header with a non-master REST/API key (e.g. change 'X-Parse-Master-Key': 'test' to 'X-Parse-REST-API-Key': 'test') so the spec exercises FilesController.prototype.createFile under regular client auth and still verifies options.metadata and options.tags.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@spec/ParseFile.spec.js`:
- Around line 2375-2397: The test "saves file with metadata and tags via
streaming upload headers" uses X-Parse-Master-Key which grants master
privileges; replace that header with a non-master REST/API key (e.g. change
'X-Parse-Master-Key': 'test' to 'X-Parse-REST-API-Key': 'test') so the spec
exercises FilesController.prototype.createFile under regular client auth and
still verifies options.metadata and options.tags.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e149a098-810a-4dcd-9f54-4326ff82f557
📒 Files selected for processing (2)
spec/ParseFile.spec.jssrc/Routers/FilesRouter.js
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Routers/FilesRouter.js
# [9.5.0-alpha.1](9.4.1...9.5.0-alpha.1) (2026-03-04) ### Features * Add support for `Parse.File.setDirectory`, `setMetadata`, `setTags` with stream-based file upload ([#10092](#10092)) ([ca666b0](ca666b0))
|
🎉 This change has been released in version 9.5.0-alpha.1 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #10092 +/- ##
==========================================
+ Coverage 92.61% 92.63% +0.01%
==========================================
Files 191 191
Lines 15784 15804 +20
Branches 180 180
==========================================
+ Hits 14619 14640 +21
+ Misses 1153 1152 -1
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Pull Request
Issue
Add support for
Parse.File.setDirectory,setMetadata,setTagswith stream-based file upload.Approach
Tasks
Summary by CodeRabbit
New Features
Tests
Chores