Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/adapter-tests/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ export default (test: AdapterMethodsTest, app: any, _errors: any, serviceName: s
} catch (error: any) {
assert.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error')
}

const updatedDoug = await service.get(doug[idProp])
assert.strictEqual(updatedDoug.name, 'Doug', 'Doug was not updated')
})

test('.update + NotFound', async () => {
Expand Down
1 change: 0 additions & 1 deletion packages/memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
},
"dependencies": {
"@feathersjs/adapter-commons": "^5.0.35",
"@feathersjs/commons": "^5.0.35",
"@feathersjs/errors": "^5.0.35",
"sift": "^17.1.3"
},
Expand Down
24 changes: 11 additions & 13 deletions packages/memory/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BadRequest, MethodNotAllowed, NotFound } from '@feathersjs/errors'
import { _ } from '@feathersjs/commons'
import {
sorter,
select,
Expand Down Expand Up @@ -75,11 +74,11 @@ export class MemoryAdapter<
const { paginate } = this.getOptions(params)
const { query, filters } = this.getQuery(params)

let values = _.values(this.store)
let values = Object.values(this.store)
const hasSkip = filters.$skip !== undefined
const hasSort = filters.$sort !== undefined
const hasLimit = filters.$limit !== undefined
const hasQuery = _.keys(query).length > 0
const hasQuery = Object.keys(query).length > 0

if (hasSort) {
values.sort(this.options.sorter(filters.$sort))
Expand Down Expand Up @@ -171,8 +170,8 @@ export class MemoryAdapter<
}

const id = (data as any)[this.id] || this._uId++
const current = _.extend({}, data, { [this.id]: id })
const result = (this.store[id] = current)
const current = { ...data, [this.id]: id }
const result = (this.store[id] = current as any)

return _select(result, params, this.id) as Result
}
Expand All @@ -182,14 +181,9 @@ export class MemoryAdapter<
throw new BadRequest("You can not replace multiple instances. Did you mean 'patch'?")
}

const oldEntry = await this._get(id)
// We don't want our id to change type if it can be coerced
const oldId = (oldEntry as any)[this.id]
const oldEntry = await this._get(id, params)

// eslint-disable-next-line eqeqeq
id = oldId == id ? oldId : id

this.store[id] = _.extend({}, data, { [this.id]: id })
this.store[id] = { ...data, [this.id]: (oldEntry as any)[this.id] } as Result

return this._get(id, params)
}
Expand All @@ -214,7 +208,11 @@ export class MemoryAdapter<
const patchEntry = (entry: Result) => {
const currentId = (entry as any)[this.id]

this.store[currentId] = _.extend(this.store[currentId], _.omit(data, this.id))
this.store[currentId] = {
...this.store[currentId],
...data,
[this.id]: (entry as any)[this.id]
}

return _select(this.store[currentId], params, this.id)
}
Expand Down