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

feat: update hapi to v20 #3245

Merged
merged 3 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/ipfs-http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"it-tar": "^1.2.2",
"it-to-buffer": "^1.0.0",
"it-to-stream": "^0.1.1",
"merge-options": "^2.0.0",
"merge-options": "^3.0.1",
"multiaddr": "^8.0.0",
"multiaddr-to-uri": "^6.0.0",
"multibase": "^3.0.0",
Expand Down
14 changes: 7 additions & 7 deletions packages/ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@
"dep-check": "aegir dep-check"
},
"dependencies": {
"@hapi/ammo": "^3.1.2",
"@hapi/boom": "^7.4.3",
"@hapi/content": "^4.1.0",
"@hapi/hapi": "^18.4.0",
"@hapi/joi": "^15.1.0",
"@hapi/ammo": "^5.0.1",
"@hapi/boom": "^9.1.0",
"@hapi/content": "^5.0.2",
"@hapi/hapi": "^20.0.0",
"abort-controller": "^3.0.0",
"any-signal": "^1.1.0",
"array-shuffle": "^1.0.1",
Expand All @@ -88,7 +87,7 @@
"fnv1a": "^1.0.1",
"get-folder-size": "^2.0.0",
"hamt-sharding": "^1.0.0",
"hapi-pino": "^6.1.0",
"hapi-pino": "^8.2.0",
"hashlru": "^2.3.0",
"interface-datastore": "^2.0.0",
"ipfs-bitswap": "^3.0.0",
Expand Down Expand Up @@ -126,6 +125,7 @@
"it-tar": "^1.2.2",
"it-to-stream": "^0.1.1",
"iterable-ndjson": "^1.1.0",
"joi": "^17.2.1",
"jsondiffpatch": "^0.4.1",
"just-safe-set": "^2.1.0",
"libp2p": "libp2p/js-libp2p#0.29.x",
Expand All @@ -145,7 +145,7 @@
"libp2p-webrtc-star": "^0.19.0",
"libp2p-websockets": "^0.14.0",
"mafmt": "^8.0.0",
"merge-options": "^2.0.0",
"merge-options": "^3.0.1",
"mortice": "^2.0.0",
"multiaddr": "^8.0.0",
"multiaddr-to-uri": "^6.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/ipfs/src/http/api/resources/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ exports.replace = {
parse: false,
output: 'stream'
},
response: {
emptyStatusCode: 200
},
pre: [{
assign: 'args',
method: async (request, h) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/ipfs/src/http/api/resources/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ exports.provide = {
override: true,
ignoreUndefined: true
})
},
response: {
emptyStatusCode: 200
}
},
async handler (request, h) {
Expand Down Expand Up @@ -255,6 +258,9 @@ exports.put = {
arg: Joi.array().length(2).items(Joi.binary()).required(),
timeout: Joi.timeout()
})
},
response: {
emptyStatusCode: 200
}
},
async handler (request, h) {
Expand Down
5 changes: 1 addition & 4 deletions packages/ipfs/src/http/api/resources/files/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ const mfsCp = {
parents: Joi.boolean().default(false),
flush: Joi.boolean().default(true),
hashAlg: Joi.string().default('sha2-256'),
cidVersion: Joi.number().integer().valid([
0,
1
]).default(0),
cidVersion: Joi.number().integer().valid(0, 1).default(0),
shardSplitThreshold: Joi.number().integer().min(0).default(1000),
timeout: Joi.timeout()
})
Expand Down
5 changes: 1 addition & 4 deletions packages/ipfs/src/http/api/resources/files/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ const mfsMkdir = {
mtimeNsecs: Joi.number().integer().min(0),
parents: Joi.boolean().default(false),
hashAlg: Joi.string().default('sha2-256'),
cidVersion: Joi.number().integer().valid([
0,
1
]).default(0),
cidVersion: Joi.number().integer().valid(0, 1).default(0),
flush: Joi.boolean().default(true),
shardSplitThreshold: Joi.number().integer().min(0).default(1000),
timeout: Joi.timeout()
Expand Down
5 changes: 1 addition & 4 deletions packages/ipfs/src/http/api/resources/files/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ const mfsMv = {
recursive: Joi.boolean().default(false),
parents: Joi.boolean().default(false),
hashAlg: Joi.string().default('sha2-256'),
cidVersion: Joi.number().integer().valid([
0,
1
]).default(0),
cidVersion: Joi.number().integer().valid(0, 1).default(0),
flush: Joi.boolean().default(true),
shardSplitThreshold: Joi.number().integer().min(0).default(1000),
timeout: Joi.timeout()
Expand Down
5 changes: 1 addition & 4 deletions packages/ipfs/src/http/api/resources/files/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ const mfsTouch = {
mtime: Joi.number().integer(),
mtimeNsecs: Joi.number().integer().min(0),
hashAlg: Joi.string().default('sha2-256'),
cidVersion: Joi.number().integer().valid([
0,
1
]).default(0),
cidVersion: Joi.number().integer().valid(0, 1).default(0),
flush: Joi.boolean().default(true),
shardSplitThreshold: Joi.number().integer().min(0).default(1000),
timeout: Joi.timeout()
Expand Down
11 changes: 2 additions & 9 deletions packages/ipfs/src/http/api/resources/files/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,11 @@ const mfsWrite = {
create: Joi.boolean().default(false),
truncate: Joi.boolean().default(false),
rawLeaves: Joi.boolean().default(false),
cidVersion: Joi.number().integer().valid([
0,
1
]).default(0),
cidVersion: Joi.number().integer().valid(0, 1).default(0),
hashAlg: Joi.string().default('sha2-256'),
parents: Joi.boolean().default(false),
progress: Joi.func(),
strategy: Joi.string().valid([
'flat',
'balanced',
'trickle'
]).default('trickle'),
strategy: Joi.string().valid('flat', 'balanced', 'trickle').default('trickle'),
flush: Joi.boolean().default(true),
reduceSingleLeafToSelf: Joi.boolean().default(false),
shardSplitThreshold: Joi.number().integer().min(0).default(1000),
Expand Down
3 changes: 3 additions & 0 deletions packages/ipfs/src/http/api/resources/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ exports.publish = {
parse: false,
output: 'stream'
},
response: {
emptyStatusCode: 200
},
pre: [{
assign: 'data',
method: async (request, h) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs/src/http/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module.exports = server => {
response: res.output.payload
}

server.logger().error(debug)
server.logger().error(res)
server.logger.error(debug)
server.logger.error(res)
}

return h.response({
Expand Down
10 changes: 5 additions & 5 deletions packages/ipfs/src/http/gateway/routes/gateway.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Joi = require('@hapi/joi')
const Joi = require('joi')
const resources = require('../resources')

module.exports = [
Expand All @@ -10,9 +10,9 @@ module.exports = [
options: {
handler: resources.gateway.handler,
validate: {
params: {
params: Joi.object({
path: Joi.string().required()
}
})
},
response: {
ranges: false // disable built-in support, handler does it manually
Expand All @@ -28,9 +28,9 @@ module.exports = [
options: {
handler: resources.gateway.handler,
validate: {
params: {
params: Joi.object({
path: Joi.string().required()
}
})
},
response: {
ranges: false // disable built-in support, handler does it manually
Expand Down
94 changes: 67 additions & 27 deletions packages/ipfs/src/http/utils/joi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Joi = require('@hapi/joi')
const Joi = require('joi')
const CID = require('cids')
const parseDuration = require('parse-duration').default
const multiaddr = require('multiaddr')
Expand Down Expand Up @@ -41,87 +41,122 @@ module.exports = Joi
.extend(
(joi) => {
return {
name: 'cid',
type: 'cid',
base: joi.any(),
pre (value, state, options) {
validate (value, helpers) {
if (helpers.schema.$_getFlag('presence') === 'required' && !value) {
return { value, errors: helpers.error('required') }
}
},
coerce (value, helpers) {
if (!value) {
return
}

return toCID(value)
return { value: toCID(value) }
}
}
},
(joi) => {
return {
name: 'ipfsPath',
type: 'ipfsPath',
base: joi.string(),
coerce (value, state, options) {
validate (value, helpers) {
if (helpers.schema.$_getFlag('presence') === 'required' && !value) {
return { value, errors: helpers.error('required') }
}
},
coerce (value, helpers) {
if (!value) {
return
}

return toIpfsPath(value)
return { value: toIpfsPath(value) }
}
}
},
(joi) => {
return {
name: 'peerId',
type: 'peerId',
base: joi.string(),
pre (value, state, options) {
validate (value, helpers) {
if (helpers.schema.$_getFlag('presence') === 'required' && !value) {
return { value, errors: helpers.error('required') }
}
},
coerce (value, helpers) {
if (!value) {
return
}

return new CID(value).toString()
return { value: new CID(value).toString() }
}
}
},
(joi) => {
return {
name: 'multiaddr',
type: 'multiaddr',
base: joi.string(),
pre (value, state, options) {
validate (value, helpers) {
if (helpers.schema.$_getFlag('presence') === 'required' && !value) {
return { value, errors: helpers.error('required') }
}
},
coerce (value, helpers) {
if (!value) {
return
}

return multiaddr(value).toString()
return { value: multiaddr(value).toString() }
}
}
},
(joi) => {
return {
name: 'timeout',
base: joi.string(),
pre (value, state, options) {
type: 'timeout',
base: joi.number(),
validate (value, helpers) {
if (helpers.schema.$_getFlag('presence') === 'required' && !value) {
return { value, errors: helpers.error('required') }
}
},
coerce (value, helpers) {
if (!value) {
return
}

return parseDuration(value)
return { value: parseDuration(value) }
}
}
},
(joi) => {
return {
name: 'cidAndPath',
type: 'cidAndPath',
base: joi.any(),
pre (value, state, options) {
validate (value, helpers) {
if (helpers.schema.$_getFlag('presence') === 'required' && !value) {
return { value, errors: helpers.error('required') }
}
},
coerce (value, helpers) {
if (!value) {
return
}

return toCidAndPath(value)
return { value: toCidAndPath(value) }
}
}
},
(joi) => {
return {
name: 'cidBase',
type: 'cidBase',
base: joi.string(),
pre (value, state, options) {
validate (value, helpers) {
if (helpers.schema.$_getFlag('presence') === 'required' && !value) {
return { value, errors: helpers.error('required') }
}
},
coerce (value, helpers) {
if (!value) {
return
}
Expand All @@ -130,20 +165,25 @@ module.exports = Joi
throw new Error('Invalid base name')
}

return value
return { value }
}
}
},
(joi) => {
return {
name: 'json',
base: joi.string(),
pre (value, state, options) {
type: 'json',
base: joi.any(),
validate (value, helpers) {
if (helpers.schema.$_getFlag('presence') === 'required' && !value) {
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
return { value, errors: helpers.error('required') }
}
},
coerce (value, helpers) {
if (!value) {
return
}

return JSON.parse(value)
return { value: JSON.parse(value) }
}
}
})
Loading