-
Notifications
You must be signed in to change notification settings - Fork 19
refactor(studio): separation of concern between app and module
#91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Suggestion:
The list() method returns documents without the fsPath property, but the app expects all items to have fsPath when building the tree.
View Details
📝 Patch Details
diff --git a/src/module/src/runtime/host.ts b/src/module/src/runtime/host.ts
index 35dda02..1fa9861 100644
--- a/src/module/src/runtime/host.ts
+++ b/src/module/src/runtime/host.ts
@@ -197,9 +197,17 @@ export function useStudioHost(user: StudioUser, repository: Repository): StudioH
return normalizeDocument(fsPath, item as DatabaseItem)
},
list: async (): Promise<DatabaseItem[]> => {
- const collections = Object.keys(useContentCollections()).filter(c => c !== 'info')
- const contents = await Promise.all(collections.map(async (collection) => {
- return await useContentCollectionQuery(collection).all() as DatabaseItem[]
+ const collections = useContentCollections()
+ const collectionNames = Object.keys(collections).filter(c => c !== 'info')
+ const contents = await Promise.all(collectionNames.map(async (collectionName) => {
+ const items = await useContentCollectionQuery(collectionName).all() as DatabaseItem[]
+ const collection = collections[collectionName]
+
+ // Normalize each item to include fsPath (similar to get() method)
+ return items.map(item => {
+ const fsPath = generateFsPathFromId(item.id, collection.source[0]!)
+ return normalizeDocument(fsPath, item)
+ })
}))
return contents.flat()
Analysis
Missing fsPath property in list() method breaks buildTree()
What fails: document.list() in src/module/src/runtime/host.ts returns items without fsPath property, causing buildTree() in src/app/src/utils/tree.ts to fail when accessing dbItem.fsPath
How to reproduce:
// Items from useContentCollectionQuery().all() lack fsPath property
const items = await host.document.list() // Returns items with id, stem, path but no fsPath
buildTree(items, null) // Throws: Cannot read properties of undefined (reading 'split')Result: Runtime error Cannot read properties of undefined (reading 'split') when buildTree() tries to access dbItem.fsPath.split('/') on line 68
Expected: Items should include fsPath property like the get() method does by calling normalizeDocument(fsPath, item)
Source: Nuxt Content docs confirm default collection fields don't include fsPath
4bfc8c0 to
3eeabf3
Compare
[Refactor] Separation of concern between app and module
Project Structure Overview
src/moduleNuxt module responsible for communication with the host (user’s website).
Handles all interactions with the SQLite database.
src/appFrontend for the Nuxt Studio application.
Provides the user interface for CRUD operations on documents and media.
Communicate with the draft.
Refactor Goal
We want a clean separation of concerns between the app and the module.
Remove all usage of db id inside the app.
The app should operate only with fsPath.
Only the module (host side) resolves fsPath → id mapping and updates the DB (base of an agnostic framework CMS in the future)
Tree note
Each tree item can be a file or a folder
Files represent real documents (association fsPath <=> id in the Nuxt Content DB)
Folders are virtual items they don’t have a corresponding id in the DB.
They exist only in the app, as a way to group related files (documents or medias)
The module doesn’t deal with folders it only processes documents (with ids).
When folder actions are performed (e.g. delete, rename, revert), the app must handle them locally and contact the host only with the document/media ids affected by that action.
Resolves #56