11import { BadRequest , MethodNotAllowed , NotFound } from '@feathersjs/errors'
2- import { _ } from '@feathersjs/commons'
32import {
43 sorter ,
54 select ,
@@ -75,11 +74,11 @@ export class MemoryAdapter<
7574 const { paginate } = this . getOptions ( params )
7675 const { query, filters } = this . getQuery ( params )
7776
78- let values = _ . values ( this . store )
77+ let values = Object . values ( this . store )
7978 const hasSkip = filters . $skip !== undefined
8079 const hasSort = filters . $sort !== undefined
8180 const hasLimit = filters . $limit !== undefined
82- const hasQuery = _ . keys ( query ) . length > 0
81+ const hasQuery = Object . keys ( query ) . length > 0
8382
8483 if ( hasSort ) {
8584 values . sort ( this . options . sorter ( filters . $sort ) )
@@ -171,8 +170,8 @@ export class MemoryAdapter<
171170 }
172171
173172 const id = ( data as any ) [ this . id ] || this . _uId ++
174- const current = _ . extend ( { } , data , { [ this . id ] : id } )
175- const result = ( this . store [ id ] = current )
173+ const current = { ... data , [ this . id ] : id }
174+ const result = ( this . store [ id ] = current as any )
176175
177176 return _select ( result , params , this . id ) as Result
178177 }
@@ -182,14 +181,9 @@ export class MemoryAdapter<
182181 throw new BadRequest ( "You can not replace multiple instances. Did you mean 'patch'?" )
183182 }
184183
185- const oldEntry = await this . _get ( id )
186- // We don't want our id to change type if it can be coerced
187- const oldId = ( oldEntry as any ) [ this . id ]
184+ const oldEntry = await this . _get ( id , params )
188185
189- // eslint-disable-next-line eqeqeq
190- id = oldId == id ? oldId : id
191-
192- this . store [ id ] = _ . extend ( { } , data , { [ this . id ] : id } )
186+ this . store [ id ] = { ...data , [ this . id ] : ( oldEntry as any ) [ this . id ] } as Result
193187
194188 return this . _get ( id , params )
195189 }
@@ -214,7 +208,11 @@ export class MemoryAdapter<
214208 const patchEntry = ( entry : Result ) => {
215209 const currentId = ( entry as any ) [ this . id ]
216210
217- this . store [ currentId ] = _ . extend ( this . store [ currentId ] , _ . omit ( data , this . id ) )
211+ this . store [ currentId ] = {
212+ ...this . store [ currentId ] ,
213+ ...data ,
214+ [ this . id ] : ( entry as any ) [ this . id ]
215+ }
218216
219217 return _select ( this . store [ currentId ] , params , this . id )
220218 }
0 commit comments