diff --git a/Data/lib/functions/getSaveDatum.ts b/Data/lib/functions/getSaveDatum.ts index 76ba85a8..7169ccfb 100644 --- a/Data/lib/functions/getSaveDatum.ts +++ b/Data/lib/functions/getSaveDatum.ts @@ -54,7 +54,9 @@ export default function getSaveDatum({ | [ T, string, - (d: DataMeta & { [key: string]: unknown }) => Partial>, + ( + d: Readonly & { [key: string]: unknown }>, + ) => Partial>, ], options: { noTouch?: boolean; @@ -171,7 +173,7 @@ export default function getSaveDatum({ const existingData = await getDatum(type, id); if (!existingData) throw new Error(`Data not found: ${type} ${id}`); - const updatedData = updater(JSON.parse(JSON.stringify(existingData))); + const updatedData = updater(existingData); const dataToSave: DataMeta & { [key: string]: unknown } = { ...(existingData ? (Object.fromEntries( diff --git a/Data/lib/types.ts b/Data/lib/types.ts index 030f4d58..767748cd 100644 --- a/Data/lib/types.ts +++ b/Data/lib/types.ts @@ -131,7 +131,9 @@ export type SaveDatum = ( | [ T, string, - (d: DataMeta & { [key: string]: unknown }) => Partial>, + ( + d: Readonly & { [key: string]: unknown }>, + ) => Partial>, ], options?: { /** Set to true to not update the `__updated_at` field. */ diff --git a/packages/data-storage-couchdb/lib/__tests__/data-storage-couchdb.test.ts b/packages/data-storage-couchdb/lib/__tests__/data-storage-couchdb.test.ts index d2eef3e1..b87e8852 100644 --- a/packages/data-storage-couchdb/lib/__tests__/data-storage-couchdb.test.ts +++ b/packages/data-storage-couchdb/lib/__tests__/data-storage-couchdb.test.ts @@ -1654,40 +1654,40 @@ describe('saveDatum', () => { }); }); - it('updates the datum while the updater function directly assigns new value to the datum', async () => { - await withContext(async context => { - const d = new CouchDBData(context); - - const collection = await d.saveDatum({ - __type: 'collection', - name: 'Collection', - icon_name: 'box', - icon_color: 'gray', - collection_reference_number: '1', - }); - - const item = await d.saveDatum({ - __type: 'item', - collection_id: collection.__id, - name: 'Item', - icon_name: 'cube-outline', - icon_color: 'gray', - }); - - await d.saveDatum([ - 'item', - item.__id || '', - datum => { - datum.name = 'Updated Item'; - return datum; - }, - ]); - - expect((await d.getDatum('item', item.__id || ''))?.name).toBe( - 'Updated Item', - ); - }); - }); + // it('updates the datum while the updater function directly assigns new value to the datum', async () => { + // await withContext(async context => { + // const d = new CouchDBData(context); + + // const collection = await d.saveDatum({ + // __type: 'collection', + // name: 'Collection', + // icon_name: 'box', + // icon_color: 'gray', + // collection_reference_number: '1', + // }); + + // const item = await d.saveDatum({ + // __type: 'item', + // collection_id: collection.__id, + // name: 'Item', + // icon_name: 'cube-outline', + // icon_color: 'gray', + // }); + + // await d.saveDatum([ + // 'item', + // item.__id || '', + // datum => { + // datum.name = 'Updated Item'; + // return datum; + // }, + // ]); + + // expect((await d.getDatum('item', item.__id || ''))?.name).toBe( + // 'Updated Item', + // ); + // }); + // }); it('returns the saved datum', async () => { await withContext(async context => {