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

Commit f08b0fd

Browse files
author
Alan Shaw
authored
fix: allow offline option casing (#561)
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>
1 parent b008a94 commit f08b0fd

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

Diff for: SPEC/NAME.md

+3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ Although not listed in the documentation, all the following APIs that actually r
2525
lifetime: // string - Time duration of the record. Default: 24h
2626
ttl: // string - Time duration this record should be cached
2727
key: // string - Name of the key to be used. Default: 'self'
28+
allowOffline: // bool - When offline, save the IPNS record to the the local datastore without broadcasting to the network instead of simply failing.
2829
}
2930
```
3031

32+
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).
33+
3134
**Returns**
3235

3336
| Type | Description |

Diff for: src/miscellaneous/resolve.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ module.exports = (createCommon, options) => {
106106
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive === true'))
107107
const { id: keyId } = await ipfs.key.gen('key-name', { type: 'rsa', size: 2048 })
108108

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

112112
return expect(await ipfs.resolve(`/ipns/${keyId}`, { recursive: true }))
113113
.to.eq(`/ipfs/${path}`)

Diff for: src/name/publish.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = (createCommon, options) => {
4343

4444
const value = fixture.cid
4545

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

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

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

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

9898
ipfs.key.gen(keyName, { type: 'rsa', size: 2048 }, function (err, key) {

Diff for: src/name/resolve.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ module.exports = (createCommon, options) => {
3939

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)