mirror of
https://github.com/typicode/json-server.git
synced 2025-08-02 19:52:20 +08:00
update dependencies (#674)
This commit is contained in:
3020
package-lock.json
generated
3020
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
62
package.json
62
package.json
@ -8,64 +8,66 @@
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "^1.15.2",
|
||||
"chalk": "^1.1.3",
|
||||
"compression": "^1.6.0",
|
||||
"body-parser": "^1.18.2",
|
||||
"chalk": "^2.3.0",
|
||||
"compression": "^1.7.1",
|
||||
"connect-pause": "^0.1.0",
|
||||
"cors": "^2.3.0",
|
||||
"cors": "^2.8.4",
|
||||
"errorhandler": "^1.2.0",
|
||||
"express": "^4.9.5",
|
||||
"express": "^4.16.2",
|
||||
"express-urlrewrite": "^1.2.0",
|
||||
"json-parse-helpfulerror": "^1.0.3",
|
||||
"lodash": "^4.11.2",
|
||||
"lodash-id": "^0.13.0",
|
||||
"lowdb": "^0.15.0",
|
||||
"method-override": "^2.1.2",
|
||||
"morgan": "^1.3.1",
|
||||
"nanoid": "^0.2.2",
|
||||
"method-override": "^2.3.10",
|
||||
"morgan": "^1.9.0",
|
||||
"nanoid": "^1.0.1",
|
||||
"object-assign": "^4.0.1",
|
||||
"please-upgrade-node": "^3.0.1",
|
||||
"pluralize": "^3.0.0",
|
||||
"request": "^2.72.0",
|
||||
"pluralize": "^7.0.0",
|
||||
"request": "^2.83.0",
|
||||
"server-destroy": "^1.0.1",
|
||||
"update-notifier": "^1.0.2",
|
||||
"update-notifier": "^2.3.0",
|
||||
"yargs": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.24.0",
|
||||
"babel-preset-env": "^1.3.2",
|
||||
"babel-register": "^6.16.3",
|
||||
"cross-env": "^2.0.1",
|
||||
"eslint": "^3.19.0",
|
||||
"eslint-config-prettier": "^2.3.0",
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"babel-register": "^6.26.0",
|
||||
"crlf": "^1.1.1",
|
||||
"cross-env": "^5.1.1",
|
||||
"eslint": "^4.10.0",
|
||||
"eslint-config-prettier": "^2.6.0",
|
||||
"eslint-config-standard": "^10.2.1",
|
||||
"eslint-plugin-import": "^2.6.1",
|
||||
"eslint-plugin-node": "^5.1.0",
|
||||
"eslint-plugin-prettier": "^2.1.2",
|
||||
"eslint-plugin-promise": "^3.5.0",
|
||||
"eslint-plugin-import": "^2.8.0",
|
||||
"eslint-plugin-node": "^5.2.1",
|
||||
"eslint-plugin-prettier": "^2.3.1",
|
||||
"eslint-plugin-promise": "^3.6.0",
|
||||
"eslint-plugin-standard": "^3.0.1",
|
||||
"husky": "^0.14.3",
|
||||
"markdown-toc": "^0.13.0",
|
||||
"markdown-toc": "^1.2.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mocha": "^3.2.0",
|
||||
"mocha": "^4.0.1",
|
||||
"os-tmpdir": "^1.0.1",
|
||||
"pkg-ok": "^1.0.1",
|
||||
"prettier": "^1.5.2",
|
||||
"rimraf": "^2.5.2",
|
||||
"prettier": "^1.7.4",
|
||||
"rimraf": "^2.6.2",
|
||||
"server-ready": "^0.3.1",
|
||||
"standard": "^8.3.0",
|
||||
"standard": "^10.0.3",
|
||||
"supertest": "^3.0.0",
|
||||
"temp-write": "^2.1.0"
|
||||
"temp-write": "^3.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm run test:cli && npm run test:server && eslint .",
|
||||
"test:cli": "npm run build && cross-env NODE_ENV=test mocha test/cli/*.js",
|
||||
"test:server": "cross-env NODE_ENV=test mocha test/server/*.js",
|
||||
"start": "babel-node src/cli/bin",
|
||||
"format": "eslint . --fix",
|
||||
"fix": "eslint . --fix",
|
||||
"build": "babel src -d lib --copy-files",
|
||||
"toc": "markdown-toc -i README.md",
|
||||
"prepublishOnly": "npm run build && pkg-ok",
|
||||
"lf": "crlf --set=LF ./bin/index.js",
|
||||
"prepublishOnly": "npm run build && npm run lf && pkg-ok",
|
||||
"precommit": "npm test"
|
||||
},
|
||||
"repository": {
|
||||
@ -97,4 +99,4 @@
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
}
|
||||
}
|
@ -67,7 +67,12 @@ function deepQuery(value, q) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else if (value.toString().toLowerCase().indexOf(q) !== -1) {
|
||||
} else if (
|
||||
value
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.indexOf(q) !== -1
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +228,10 @@ module.exports = (db, name, opts) => {
|
||||
function show(req, res, next) {
|
||||
const _embed = req.query._embed
|
||||
const _expand = req.query._expand
|
||||
const resource = db.get(name).getById(req.params.id).value()
|
||||
const resource = db
|
||||
.get(name)
|
||||
.getById(req.params.id)
|
||||
.value()
|
||||
|
||||
if (resource) {
|
||||
// Clone resource to avoid making changes to the underlying object
|
||||
@ -250,7 +253,10 @@ module.exports = (db, name, opts) => {
|
||||
|
||||
// POST /name
|
||||
function create(req, res, next) {
|
||||
const resource = db.get(name).insert(req.body).value()
|
||||
const resource = db
|
||||
.get(name)
|
||||
.insert(req.body)
|
||||
.value()
|
||||
|
||||
res.setHeader('Access-Control-Expose-Headers', 'Location')
|
||||
res.location(`${getFullURL(req)}/${resource.id}`)
|
||||
@ -283,14 +289,20 @@ module.exports = (db, name, opts) => {
|
||||
|
||||
// DELETE /name/:id
|
||||
function destroy(req, res, next) {
|
||||
const resource = db.get(name).removeById(req.params.id).value()
|
||||
const resource = db
|
||||
.get(name)
|
||||
.removeById(req.params.id)
|
||||
.value()
|
||||
|
||||
// Remove dependents documents
|
||||
console.log({ opts })
|
||||
const removable = db._.getRemovable(db.getState(), opts)
|
||||
console.log(removable)
|
||||
removable.forEach(item => {
|
||||
db.get(item.name).removeById(item.id).value()
|
||||
db
|
||||
.get(item.name)
|
||||
.removeById(item.id)
|
||||
.value()
|
||||
})
|
||||
|
||||
if (resource) {
|
||||
@ -302,7 +314,10 @@ module.exports = (db, name, opts) => {
|
||||
|
||||
const w = write(db)
|
||||
|
||||
router.route('/').get(list).post(create, w)
|
||||
router
|
||||
.route('/')
|
||||
.get(list)
|
||||
.post(create, w)
|
||||
|
||||
router
|
||||
.route('/:id')
|
||||
|
@ -25,7 +25,10 @@ module.exports = (db, name) => {
|
||||
if (req.method === 'PUT') {
|
||||
db.set(name, req.body).value()
|
||||
} else {
|
||||
db.get(name).assign(req.body).value()
|
||||
db
|
||||
.get(name)
|
||||
.assign(req.body)
|
||||
.value()
|
||||
}
|
||||
|
||||
res.locals.data = db.get(name).value()
|
||||
@ -34,7 +37,12 @@ module.exports = (db, name) => {
|
||||
|
||||
const w = write(db)
|
||||
|
||||
router.route('/').get(show).post(create, w).put(update, w).patch(update, w)
|
||||
router
|
||||
.route('/')
|
||||
.get(show)
|
||||
.post(create, w)
|
||||
.put(update, w)
|
||||
.patch(update, w)
|
||||
|
||||
return router
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ const osTmpdir = require('os-tmpdir')
|
||||
const tempWrite = require('temp-write')
|
||||
const mkdirp = require('mkdirp')
|
||||
const rimraf = require('rimraf')
|
||||
const express = require('express')
|
||||
const serverReady = require('server-ready')
|
||||
|
||||
let PORT = 3100
|
||||
@ -76,13 +75,16 @@ describe('cli', () => {
|
||||
})
|
||||
|
||||
it('should update JSON file', done => {
|
||||
request.post('/posts').send({ title: 'hello' }).end(() => {
|
||||
setTimeout(() => {
|
||||
const str = fs.readFileSync(dbFile, 'utf8')
|
||||
assert(str.indexOf('hello') !== -1)
|
||||
done()
|
||||
}, 1000)
|
||||
})
|
||||
request
|
||||
.post('/posts')
|
||||
.send({ title: 'hello' })
|
||||
.end(() => {
|
||||
setTimeout(() => {
|
||||
const str = fs.readFileSync(dbFile, 'utf8')
|
||||
assert(str.indexOf('hello') !== -1)
|
||||
done()
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -97,16 +99,10 @@ describe('cli', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('http://localhost:8080/db', () => {
|
||||
describe('remote db', () => {
|
||||
beforeEach(done => {
|
||||
const fakeServer = express()
|
||||
fakeServer.get('/db', (req, res) => {
|
||||
res.jsonp({ posts: [] })
|
||||
})
|
||||
fakeServer.listen(8080, () => {
|
||||
child = cli(['http://localhost:8080/db'])
|
||||
serverReady(PORT, done)
|
||||
})
|
||||
child = cli(['https://jsonplaceholder.typicode.com/db'])
|
||||
serverReady(PORT, done)
|
||||
})
|
||||
|
||||
it('should support URL file', done => {
|
||||
@ -170,7 +166,10 @@ describe('cli', () => {
|
||||
})
|
||||
|
||||
it('should have post body in middleware', done => {
|
||||
request.post('/posts').send({ name: 'test' }).expect('name', 'test', done)
|
||||
request
|
||||
.post('/posts')
|
||||
.send({ name: 'test' })
|
||||
.expect('name', 'test', done)
|
||||
})
|
||||
})
|
||||
|
||||
@ -246,15 +245,18 @@ describe('cli', () => {
|
||||
})
|
||||
|
||||
it('should not set Content-Encoding to gzip', done => {
|
||||
request.get('/posts').expect(200).end(function(err, res) {
|
||||
if (err) {
|
||||
done(err)
|
||||
} else if ('content-encoding' in res.headers) {
|
||||
done(new Error('Content-Encoding is set to gzip'))
|
||||
} else {
|
||||
done()
|
||||
}
|
||||
})
|
||||
request
|
||||
.get('/posts')
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) {
|
||||
done(err)
|
||||
} else if ('content-encoding' in res.headers) {
|
||||
done(new Error('Content-Encoding is set to gzip'))
|
||||
} else {
|
||||
done()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -106,7 +106,10 @@ describe('Server with custom foreign key', () => {
|
||||
|
||||
describe('DELETE /:resource/:id', () => {
|
||||
it('should respond with empty data, destroy resource and dependent resources', async () => {
|
||||
await request(server).del('/posts/1').expect({}).expect(200)
|
||||
await request(server)
|
||||
.del('/posts/1')
|
||||
.expect({})
|
||||
.expect(200)
|
||||
assert.equal(db.posts.length, 1)
|
||||
assert.equal(db.comments.length, 1)
|
||||
})
|
||||
|
@ -111,7 +111,9 @@ describe('Server', () => {
|
||||
.expect(200))
|
||||
|
||||
it('should respond with 404 if resource is not found', () =>
|
||||
request(server).get('/undefined').expect(404))
|
||||
request(server)
|
||||
.get('/undefined')
|
||||
.expect(404))
|
||||
})
|
||||
|
||||
describe('GET /:resource?attr=&attr=', () => {
|
||||
@ -590,7 +592,10 @@ describe('Server', () => {
|
||||
|
||||
describe('DELETE /:resource/:id', () => {
|
||||
it('should respond with empty data, destroy resource and dependent resources', async () => {
|
||||
await request(server).del('/posts/1').expect({}).expect(200)
|
||||
await request(server)
|
||||
.del('/posts/1')
|
||||
.expect({})
|
||||
.expect(200)
|
||||
assert.equal(db.posts.length, 1)
|
||||
assert.equal(db.comments.length, 3)
|
||||
})
|
||||
@ -646,25 +651,37 @@ describe('Server', () => {
|
||||
|
||||
describe('Rewriter', () => {
|
||||
it('should rewrite using prefix', () =>
|
||||
request(server).get('/api/posts/1').expect(db.posts[0]))
|
||||
request(server)
|
||||
.get('/api/posts/1')
|
||||
.expect(db.posts[0]))
|
||||
|
||||
it('should rewrite using params', () =>
|
||||
request(server).get('/blog/posts/1/show').expect(db.posts[0]))
|
||||
request(server)
|
||||
.get('/blog/posts/1/show')
|
||||
.expect(db.posts[0]))
|
||||
|
||||
it('should rewrite using query without params', () => {
|
||||
const expectedPost = _.cloneDeep(db.posts[0])
|
||||
expectedPost.comments = [db.comments[0], db.comments[1]]
|
||||
return request(server).get('/firstpostwithcomments').expect(expectedPost)
|
||||
return request(server)
|
||||
.get('/firstpostwithcomments')
|
||||
.expect(expectedPost)
|
||||
})
|
||||
|
||||
it('should rewrite using params and query', () =>
|
||||
request(server).get('/comments/special/1-quux').expect([db.comments[4]]))
|
||||
request(server)
|
||||
.get('/comments/special/1-quux')
|
||||
.expect([db.comments[4]]))
|
||||
|
||||
it('should rewrite query params', () =>
|
||||
request(server).get('/articles?_id=1').expect(db.posts[0]))
|
||||
request(server)
|
||||
.get('/articles?_id=1')
|
||||
.expect(db.posts[0]))
|
||||
|
||||
it('should expose routes', () =>
|
||||
request(server).get('/__rules').expect(rewriterRules))
|
||||
request(server)
|
||||
.get('/__rules')
|
||||
.expect(rewriterRules))
|
||||
})
|
||||
|
||||
describe('router.render', () => {
|
||||
|
@ -22,20 +22,31 @@ describe('Server', () => {
|
||||
|
||||
describe('GET /:resource', () => {
|
||||
it('should respond with corresponding resource', () =>
|
||||
request(server).get('/user').expect(db.user).expect(200))
|
||||
request(server)
|
||||
.get('/user')
|
||||
.expect(db.user)
|
||||
.expect(200))
|
||||
})
|
||||
|
||||
describe('POST /:resource', () => {
|
||||
it('should create resource', () => {
|
||||
const user = { name: 'bar' }
|
||||
return request(server).post('/user').send(user).expect(user).expect(201)
|
||||
return request(server)
|
||||
.post('/user')
|
||||
.send(user)
|
||||
.expect(user)
|
||||
.expect(201)
|
||||
})
|
||||
})
|
||||
|
||||
describe('PUT /:resource', () => {
|
||||
it('should update resource', () => {
|
||||
const user = { name: 'bar' }
|
||||
return request(server).put('/user').send(user).expect(user).expect(200)
|
||||
return request(server)
|
||||
.put('/user')
|
||||
.send(user)
|
||||
.expect(user)
|
||||
.expect(200)
|
||||
})
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user