Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: allow offline option casing (#561)
Browse files Browse the repository at this point in the history
Should be camel case in core `allowOffline: true` and kebab case in querystring `?allow-offline=true` and CLI `--allow-offline`.

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
alanshaw committed Nov 19, 2019
1 parent b008a94 commit f08b0fd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
3 changes: 3 additions & 0 deletions SPEC/NAME.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ Although not listed in the documentation, all the following APIs that actually r
lifetime: // string - Time duration of the record. Default: 24h
ttl: // string - Time duration this record should be cached
key: // string - Name of the key to be used. Default: 'self'
allowOffline: // bool - When offline, save the IPNS record to the the local datastore without broadcasting to the network instead of simply failing.
}
```

Note: `allowOffline` option is not yet implemented in js-ipfs. See tracking issue [ipfs/js-ipfs#1997](https://github.com/ipfs/js-ipfs/issues/1997).

**Returns**

| Type | Description |
Expand Down
4 changes: 2 additions & 2 deletions src/miscellaneous/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ module.exports = (createCommon, options) => {
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive === true'))
const { id: keyId } = await ipfs.key.gen('key-name', { type: 'rsa', size: 2048 })

await ipfs.name.publish(path, { 'allow-offline': true })
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name', resolve: false })
await ipfs.name.publish(path, { allowOffline: true })
await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name', resolve: false })

return expect(await ipfs.resolve(`/ipns/${keyId}`, { recursive: true }))
.to.eq(`/ipfs/${path}`)
Expand Down
8 changes: 4 additions & 4 deletions src/name/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = (createCommon, options) => {

const value = fixture.cid

ipfs.name.publish(value, { 'allow-offline': true }, (err, res) => {
ipfs.name.publish(value, { allowOffline: true }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res.name).to.equal(nodeId)
Expand All @@ -55,7 +55,7 @@ module.exports = (createCommon, options) => {

it('should publish correctly with the lifetime option and resolve', async () => {
const [{ path }] = await ipfs.add(Buffer.from('should publish correctly with the lifetime option and resolve'))
await ipfs.name.publish(path, { 'allow-offline': true, resolve: false, lifetime: '2h' })
await ipfs.name.publish(path, { allowOffline: true, resolve: false, lifetime: '2h' })

return expect(await ipfs.name.resolve(`/ipns/${nodeId}`)).to.eq(`/ipfs/${path}`)
})
Expand All @@ -70,7 +70,7 @@ module.exports = (createCommon, options) => {
lifetime: '1m',
ttl: '10s',
key: 'self',
'allow-offline': true
allowOffline: true
}

ipfs.name.publish(value, options, (err, res) => {
Expand All @@ -92,7 +92,7 @@ module.exports = (createCommon, options) => {
lifetime: '24h',
ttl: '10s',
key: keyName,
'allow-offline': true
allowOffline: true
}

ipfs.key.gen(keyName, { type: 'rsa', size: 2048 }, function (err, key) {
Expand Down
24 changes: 12 additions & 12 deletions src/name/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ module.exports = (createCommon, options) => {

const { id: keyId } = await ipfs.key.gen('key-name-default', { type: 'rsa', size: 2048 })

await ipfs.name.publish(path, { 'allow-offline': true })
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name-default' })
await ipfs.name.publish(path, { allowOffline: true })
await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name-default' })

return expect(await ipfs.name.resolve(`/ipns/${keyId}`))
.to.eq(`/ipfs/${path}`)
Expand All @@ -50,7 +50,7 @@ module.exports = (createCommon, options) => {
this.timeout(20 * 1000)
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record from cidv1b32'))
const { id: peerId } = await ipfs.id()
await ipfs.name.publish(path, { 'allow-offline': true })
await ipfs.name.publish(path, { allowOffline: true })

// Represent Peer ID as CIDv1 Base32
// https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md
Expand All @@ -62,7 +62,7 @@ module.exports = (createCommon, options) => {

it('should resolve a record recursive === false', async () => {
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive === false'))
await ipfs.name.publish(path, { 'allow-offline': true })
await ipfs.name.publish(path, { allowOffline: true })
return expect(await ipfs.name.resolve(`/ipns/${nodeId}`, { recursive: false }))
.to.eq(`/ipfs/${path}`)
})
Expand All @@ -74,8 +74,8 @@ module.exports = (createCommon, options) => {

const { id: keyId } = await ipfs.key.gen('key-name', { type: 'rsa', size: 2048 })

await ipfs.name.publish(path, { 'allow-offline': true })
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name' })
await ipfs.name.publish(path, { allowOffline: true })
await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name' })

return expect(await ipfs.name.resolve(`/ipns/${keyId}`, { recursive: true }))
.to.eq(`/ipfs/${path}`)
Expand All @@ -88,16 +88,16 @@ module.exports = (createCommon, options) => {

const { id: keyId } = await ipfs.key.gen('key-name-remainder-default', { type: 'rsa', size: 2048 })

await ipfs.name.publish(path, { 'allow-offline': true })
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name-remainder-default' })
await ipfs.name.publish(path, { allowOffline: true })
await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name-remainder-default' })

return expect(await ipfs.name.resolve(`/ipns/${keyId}/remainder/file.txt`))
.to.eq(`/ipfs/${path}/remainder/file.txt`)
})

it('should resolve a record recursive === false with remainder', async () => {
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive = false with remainder'))
await ipfs.name.publish(path, { 'allow-offline': true })
await ipfs.name.publish(path, { allowOffline: true })
return expect(await ipfs.name.resolve(`/ipns/${nodeId}/remainder/file.txt`, { recursive: false }))
.to.eq(`/ipfs/${path}/remainder/file.txt`)
})
Expand All @@ -109,8 +109,8 @@ module.exports = (createCommon, options) => {

const { id: keyId } = await ipfs.key.gen('key-name-remainder', { type: 'rsa', size: 2048 })

await ipfs.name.publish(path, { 'allow-offline': true })
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name-remainder' })
await ipfs.name.publish(path, { allowOffline: true })
await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name-remainder' })

return expect(await ipfs.name.resolve(`/ipns/${keyId}/remainder/file.txt`, { recursive: true }))
.to.eq(`/ipfs/${path}/remainder/file.txt`)
Expand All @@ -120,7 +120,7 @@ module.exports = (createCommon, options) => {
const publishOptions = {
lifetime: '100ms',
ttl: '10s',
'allow-offline': true
allowOffline: true
}

// we add new data instead of re-using fixture to make sure lifetime handling doesn't break
Expand Down

0 comments on commit f08b0fd

Please sign in to comment.