Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Aug 11, 2016
1 parent e4d335f commit 394bbd9
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage
doc
dist/*.js
dist/*.map
*.log
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jason Dobry <[email protected]> Jason Dobry <[email protected]>
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
# The email address is not required for organizations.
#
Jason Dobry <[email protected]>
Nick Escallon <[email protected]>
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
##### 0.8.0 - 10 August 2016

###### Breaking changes
- Requiring latest rc of js-data

###### Backwards compatible changes
- Updated dependencies

###### Bug fixes
- #4, #5 response metadata not getting passed to findAll by @nickescallon

##### 0.7.4 - 07 July 2016

###### Backwards compatible changes
Expand Down
10 changes: 6 additions & 4 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# People who have contributed to the js-data-adapter project.
# This is the official list of js-data-adapter project contributors.
#
# Names should be added to this file as:
# [commit count] Name <email address>
1 Jason Dobry <[email protected]>
# Names are formatted as:
# Name [email address]
#
Jason Dobry <[email protected]>
Nick Escallon <[email protected]>
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-data-adapter",
"description": "Base adapter class that all other js-data adapters extend.",
"version": "0.7.4",
"version": "0.8.0",
"homepage": "https://github.com/js-data/js-data-adapter",
"repository": {
"type": "git",
Expand Down Expand Up @@ -64,17 +64,17 @@
"release": "npm test && repo-tools updates && repo-tools changelog && repo-tools authors"
},
"peerDependencies": {
"js-data": "^3.0.0-beta.10"
"js-data": "^3.0.0-rc.4"
},
"dependencies": {
"chai": "^3.5.0",
"mocha": "^2.5.3",
"sinon": "^1.17.4"
"mocha": "^3.0.2",
"sinon": "^1.17.5"
},
"devDependencies": {
"babel-plugin-syntax-async-functions": "6.8.0",
"babel-plugin-transform-regenerator": "6.9.0",
"babel-plugin-syntax-async-functions": "6.13.0",
"babel-plugin-transform-regenerator": "6.11.4",
"babel-preset-stage-0": "6.5.0",
"js-data-repo-tools": "0.5.5"
"js-data-repo-tools": "0.5.6"
}
}
25 changes: 25 additions & 0 deletions test/findAll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ export default function (options) {
assert.equal(users2[0].name, 'John', users2[0].name)
})

it('should filter users with raw option', async function () {
let props = { name: 'John' }
assert.debug('findAll', User.name, { age: 30 })
const result = await adapter.findAll(User, { age: 30 }, { raw: true })
const users = result.data
assert.debug('found', User.name, users)
assert.equal(result.mock, true, 'should have metadata')
assert.equal(users.length, 0, 'users.length')

assert.debug('create', User.name, props)
const user = await adapter.create(User, props)
assert.debug('created', User.name, user)
const userId = user[User.idAttribute]

assert.debug('findAll', User.name, { name: 'John' })
const result2 = await adapter.findAll(User, { name: 'John' }, { raw: true })
const users2 = result2.data
assert.equal(result2.mock, true, 'should have metadata')
assert.debug('found', User.name, users2)

assert.equal(users2.length, 1, 'users2.length')
assert.equal(users2[0][User.idAttribute], userId, 'users2[0][User.idAttribute]')
assert.equal(users2[0].name, 'John', users2[0].name)
})

if (options.hasFeature('findAllInOp')) {
it('should filter users using the "in" operator', async function () {
var users = await adapter.findAll(User, {
Expand Down
26 changes: 15 additions & 11 deletions test/mockAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ function getCollection (mapper) {
return collection
}

function makeResult () {
return { mock: true }
}

addHiddenPropsToTarget(MockAdapter.prototype, {
_count: function (mapper, query) {
var collection = getCollection(mapper)
var records = collection.filter(query || {})
return [records.length, {}]
return [records.length, makeResult()]
},
_create: function (mapper, props) {
props = plainCopy(props)
Expand All @@ -58,7 +62,7 @@ addHiddenPropsToTarget(MockAdapter.prototype, {
}
var created = JSON.parse(JSON.stringify(props))
getCollection(mapper).add(created)
return [created, {}]
return [created, makeResult()]
},
_createMany: function (mapper, props) {
props = plainCopy(props)
Expand All @@ -70,25 +74,25 @@ addHiddenPropsToTarget(MockAdapter.prototype, {
created.push(JSON.parse(JSON.stringify(_props)))
})
getCollection(mapper).add(created)
return [created, {}]
return [created, makeResult()]
},
_destroy: function (mapper, id) {
getCollection(mapper).remove(id)
return [undefined, {}]
return [undefined, makeResult()]
},
_destroyAll: function (mapper, query) {
var collection = getCollection(mapper)
var records = collection.filter(query || {})
records.forEach(function (record) {
collection.remove(record[mapper.idAttribute])
})
return [undefined, {}]
return [undefined, makeResult()]
},
_find: function (mapper, id) {
return [getCollection(mapper).get(id), {}]
return [getCollection(mapper).get(id), makeResult()]
},
_findAll: function (mapper, query) {
return [getCollection(mapper).filter(query || {}), {}]
return [getCollection(mapper).filter(query || {}), makeResult()]
},
_sum: function (mapper, field, query) {
var collection = getCollection(mapper)
Expand All @@ -98,7 +102,7 @@ addHiddenPropsToTarget(MockAdapter.prototype, {
sum += record[field] || 0
})

return [sum, {}]
return [sum, makeResult()]
},
_update: function (mapper, id, props) {
props = plainCopy(props)
Expand All @@ -108,22 +112,22 @@ addHiddenPropsToTarget(MockAdapter.prototype, {
} else {
throw new Error('Not Found')
}
return [record, {}]
return [record, makeResult()]
},
_updateAll: function (mapper, props, query) {
props = plainCopy(props)
var records = getCollection(mapper).filter(query || {})
records.forEach(function (record) {
deepMixIn(record, props || {})
})
return [records, {}]
return [records, makeResult()]
},
_updateMany: function (mapper, records) {
var collection = getCollection(mapper)
records || (records = [])
records.forEach(function (record, i) {
records[i] = collection.add(record)
})
return [records, {}]
return [records, makeResult()]
}
})

0 comments on commit 394bbd9

Please sign in to comment.