fix: fix csv file collections
π Linked issue
Close #3511
β Type of change
- [ ] π Documentation (updates to the documentation or readme)
- [x] π Bug fix (a non-breaking change that fixes an issue)
- [ ] π Enhancement (improving an existing functionality like performance)
- [ ] β¨ New feature (a non-breaking change that adds functionality)
- [ ] β οΈ Breaking change (fix or feature that would cause existing functionality to change)
π Description
Currently, CSV collections donβt behave as described in the documentation. Instead of allowing each CSV file to contain multiple entries (as the documentation states), the current implementation treats each CSV file as a single piece of content.
π Checklist
- [x] I have linked an issue or discussion.
- [ ] I have updated the documentation accordingly.
@Jasonzyt is attempting to deploy a commit to the NuxtLabs Team on Vercel.
A member of the Team first needs to authorize it.
Thanks for the PR @Jasonzyt It shame that I've missed this changes in documentation update. Documentation is wrong. But this behavior is not planned to support. Instead module could support this behavior only for single file CSV collections.
people: defineCollection({
type: "data",
source: "org/people.csv",
schema: z.object({
"name": z.string(),
"email": z.string().email(),
}),
}),
It is important to create 1 to 1 and predictable mapping between files in content directory and documents in database. Splitting CSV files outside of collection source login, breaks this predictability.
In my case, I only need single file CSV support. I agree with you, so documentation should be updated.
My PR can implement single CSV support, but tbh some logic needs to be optimized. And I think CSV data type support (currently only string) should be added too.
I'll update your PR, we can test and improve
@Jasonzyt Could you check and test the behavior? We need to update docs to document both single file and multi file behaviors
And the facts prove this point: after installing the latest package, errors occurred.
In my case
const { data } = await useAsyncData("albumsMeta", () => {
return queryCollection("albumsMeta").order("updated", "DESC").all();
});
returns
[ { id: 'albumsMeta/albums-meta/albums-meta.csv',
cover: null,
description: null,
extension: 'csv',
meta: { path: '/albums-meta/albums-meta', body: [Array], title: 'Albums Meta' },
name: null,
stem: 'albums-meta/albums-meta',
updated: null,
urlFormat: null,
__hash__: 'qZyKG0MlhJb1M0gDHO6L8sGT9FxtlwB_nASlz1K0ooM' } ]
This is exactly the bug mentioned by #3511
@Jasonzyt could you share your reproduction repository? or provide minimal one?
Here's my repo: https://github.com/Jasonzyt/gallery
@Jasonzyt There was a mistake in a string, should be good now. Try with https://pkg.pr.new/@nuxt/content@0f6d610
I installed npm i https://pkg.pr.new/@nuxt/content@3513 and it worked fine. But after few hours when i am installing this package in my different project it give the same error as earlier.
Edit:
And after installing npm i https://pkg.pr.new/@nuxt/content@0f6d610 its giving the same problem
Please solve this problem urgently. I have projects to submit
@tazim404
Try https://pkg.pr.new/@nuxt/content@c1cefd2 ?
c1cefd2 works for me
but the later changes broke it
@Jasonzyt There was a mistake in a string, should be good now. Try with
https://pkg.pr.new/@nuxt/content@0f6d610
@farnabaz Still the same bug behaved like #3511
@Jasonzyt I checked with your projects and it works as expected with single file sources.
try with npm i https://pkg.pr.new/@nuxt/content@f790439
Note: I had to remove styles and some other deps because I was facing issue with oxc in you repo
Note2: It is not recommended to use useAsyncData outside of script setup. this utility is designed to use directly in script
Okay, I found the problem:
You can't use **.csv in the content.config.ts
export default defineContentConfig({
collections: {
albumsMeta: defineCollection({
type: "data",
+ source: "test.csv",
- source: "test/**.csv",
schema: z.object({
id: z.string(),
name: z.string(),
description: z.string(),
cover: z.string(),
updated: z.string(),
urlFormat: z.string(),
}),
}),
...defineAlbumCollections(),
},
});
Now everything works well!
@farnabaz Thanks for the review! I think we should complete docs before merging
@farnabaz It seems there's some bug parsing multiple .csv files Single .csv file works well The currently behavior is not matched with the newly updated docs.
@farnabaz Okay now I understand everything. Sry for my misunderstand of your newly updated docs. TBH some code is really confusing. I spent hours reading it and finally figured it out. I just reorganized the docs and make it clearer. Now I think the PR is ready to merge! Thanks for your work.