fix(queryCollectionSearchSections): fix options types#3705
fix(queryCollectionSearchSections): fix options types#3705hendrikheil wants to merge 2 commits intonuxt:mainfrom
Conversation
|
@hendrikheil is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe PR makes Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
docs/content/docs/4.utils/4.query-collection-search-sections.md (1)
26-26: Type signature in documentation is incomplete.The function signature in the
Typesection doesn't includeextraFieldsin the options, but theAPIsection below documents it. Update the type signature for consistency:📝 Suggested fix
-function queryCollectionSearchSections(collection: keyof Collections, opts?: { ignoredTags?: string[], minHeading?: string, maxHeading?: string }): ChainablePromise<T, Section[]> +function queryCollectionSearchSections(collection: keyof Collections, opts?: { ignoredTags?: string[], minHeading?: string, maxHeading?: string, extraFields?: string[] }): ChainablePromise<T, Section[]>src/runtime/internal/search.ts (1)
30-40: Pipeline failure: Type error when spreadingextraFieldsintoselect().The widened type
(string | symbol | number)[]forextraFieldscauses a TypeScript error at line 37 becauseselect()expectskeyof T. Since you're already castingextraFields as string[]at line 40, apply a similar cast when passing toselect():🔧 Proposed fix
const documents = await queryBuilder .where('extension', '=', 'md') - .select('path', 'body', 'description', 'title', ...(extraFields || [])) + .select('path', 'body', 'description', 'title', ...((extraFields || []) as string[])) .all()
379e0ec to
44050d8
Compare
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/content/docs/4.utils/4.query-collection-search-sections.md (1)
48-55: Clarify thatextraFieldsextends the section object properties.The documentation for the return value (lines 49-55) lists the standard properties (
id,title,titles,content,level) but doesn't mention that whenextraFieldsis provided, those additional fields will also be present in each section object.Consider adding a note like:
- `extraFields`: An array of additional fields from the collection items to include in the section objects. - Returns: A Promise that resolves to an array of searchable sections. Each section is an object with the following properties: - `id`: A unique identifier for the section. - `title`: The title of the section (usually the heading text). - `titles`: An array of parent section titles, representing the hierarchy. - `content`: The textual content of the section. - `level`: The heading level (1-6) of the section, where 1 is the highest level. - Any additional fields specified in the `extraFields` option will also be included in each section.This helps users understand that the section objects are dynamically extended based on the
extraFieldsoption.
🧹 Nitpick comments (1)
docs/content/docs/4.utils/4.query-collection-search-sections.md (1)
26-26: Consider more specific types for heading level options.The
minHeadingandmaxHeadingoptions are currently typed asstring, which allows any string value. For better type safety and developer experience, consider using a union type:minHeading?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' maxHeading?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'This would provide autocomplete suggestions and catch invalid values at compile time.
Thanks for the PR @hendrikheil |
🔗 Linked issue
❓ Type of change
📚 Description
This PR updates the server and client types for
queryCollectionSearchSections. It adds missing options likeminHeading,maxHeadingandextraFieldsand removes an unused optionsseparators, which had no effect on the actual query.I've also added a test for the extraFields behavior to ensure it actually works as expected.
It might be useful to export the options of
generateSearchSectionsas a type so that they don't have to be duplicated two additional times?📝 Checklist