@@ -3,7 +3,7 @@ import { ensure } from './utils/ensure'
33import type { CollectionInfo , CollectionItemBase , CollectionSource , DatabaseAdapter } from '@nuxt/content'
44import type { ContentDatabaseAdapter } from '../types/content'
55import { getCollectionByFilePath , generateIdFromFsPath , generateRecordDeletion , generateRecordInsert , generateFsPathFromId , getCollectionById } from './utils/collection'
6- import { populateDocumentbasedOnCollectionInfo , isDocumentMatchingContent , normalizeDocument , generateDocumentFromContent , generateContentFromDocument , areDocumentsEqual , pickReservedKeysFromDocument , removeReservedKeysFromDocument } from './utils/document'
6+ import { normalizeDocument , isDocumentMatchingContent , generateDocumentFromContent , generateContentFromDocument , areDocumentsEqual , pickReservedKeysFromDocument , removeReservedKeysFromDocument } from './utils/document'
77import { kebabCase } from 'scule'
88import type { StudioHost , StudioUser , DatabaseItem , MediaItem , Repository } from 'nuxt-studio/app'
99import type { RouteLocationNormalized , Router } from 'vue-router'
@@ -194,7 +194,14 @@ export function useStudioHost(user: StudioUser, repository: Repository): StudioH
194194 const id = generateIdFromFsPath ( fsPath , collectionInfo )
195195 const item = await useContentCollectionQuery ( collectionInfo . name ) . where ( 'id' , '=' , id ) . first ( )
196196
197- return item ? normalizeDocument ( fsPath , item as DatabaseItem ) : undefined
197+ if ( ! item ) {
198+ return undefined
199+ }
200+
201+ return {
202+ ...item ,
203+ fsPath,
204+ }
198205 } ,
199206 list : async ( ) : Promise < DatabaseItem [ ] > => {
200207 const collections = Object . values ( useContentCollections ( ) ) . filter ( collection => collection . name !== 'info' )
@@ -205,7 +212,10 @@ export function useStudioHost(user: StudioUser, repository: Repository): StudioH
205212 const source = getCollectionSourceById ( document . id , collection . source )
206213 const fsPath = generateFsPathFromId ( document . id , source ! )
207214
208- return normalizeDocument ( fsPath , document )
215+ return {
216+ ...document ,
217+ fsPath,
218+ }
209219 } )
210220 } ) )
211221
@@ -225,11 +235,14 @@ export function useStudioHost(user: StudioUser, repository: Repository): StudioH
225235 }
226236
227237 const document = await generateDocumentFromContent ( id , content )
228- const collectionDocument = populateDocumentbasedOnCollectionInfo ( id , collectionInfo , document ! )
238+ const normalizedDocument = normalizeDocument ( id , collectionInfo , document ! )
229239
230- await host . document . db . upsert ( fsPath , collectionDocument )
240+ await host . document . db . upsert ( fsPath , normalizedDocument )
231241
232- return normalizeDocument ( fsPath , collectionDocument ! )
242+ return {
243+ ...normalizedDocument ,
244+ fsPath,
245+ }
233246 } ,
234247 upsert : async ( fsPath : string , document : CollectionItemBase ) => {
235248 const collectionInfo = getCollectionByFilePath ( fsPath , useContentCollections ( ) )
@@ -239,10 +252,10 @@ export function useStudioHost(user: StudioUser, repository: Repository): StudioH
239252
240253 const id = generateIdFromFsPath ( fsPath , collectionInfo )
241254
242- const doc = populateDocumentbasedOnCollectionInfo ( id , collectionInfo , document )
255+ const normalizedDocument = normalizeDocument ( id , collectionInfo , document )
243256
244257 await useContentDatabaseAdapter ( collectionInfo . name ) . exec ( generateRecordDeletion ( collectionInfo , id ) )
245- await useContentDatabaseAdapter ( collectionInfo . name ) . exec ( generateRecordInsert ( collectionInfo , doc ) )
258+ await useContentDatabaseAdapter ( collectionInfo . name ) . exec ( generateRecordInsert ( collectionInfo , normalizedDocument ) )
246259 } ,
247260 delete : async ( fsPath : string ) => {
248261 const collection = getCollectionByFilePath ( fsPath , useContentCollections ( ) )
0 commit comments