Skip to content

Commit 4c6caa2

Browse files
authored
fix: @feathersjs/memory update with query (#3617)
1 parent f5276c4 commit 4c6caa2

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/adapter-tests/src/methods.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ export default (test: AdapterMethodsTest, app: any, _errors: any, serviceName: s
292292
} catch (error: any) {
293293
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error')
294294
}
295+
296+
const updatedDoug = await service.get(doug[idProp])
297+
assert.strictEqual(updatedDoug.name, 'Doug', 'Doug was not updated')
295298
})
296299

297300
test('.update + NotFound', async () => {

packages/memory/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
},
5151
"dependencies": {
5252
"@feathersjs/adapter-commons": "^5.0.35",
53-
"@feathersjs/commons": "^5.0.35",
5453
"@feathersjs/errors": "^5.0.35",
5554
"sift": "^17.1.3"
5655
},

packages/memory/src/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { BadRequest, MethodNotAllowed, NotFound } from '@feathersjs/errors'
2-
import { _ } from '@feathersjs/commons'
32
import {
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

Comments
 (0)