This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove non default ipld formats in the browser (#1980)
BREAKING CHANGE: Browser application bundles now include only `ipld-dag-pb`, `ipld-dag-cbor` and `ipld-raw` IPLD codecs. Other codecs should be added manually, see https://github.com/ipfs/js-ipfs/blob/master/README.md#optionsipld for details. * In Node.js `require('ipfs')` * all IPLD formats included * In browser application bundle `require('ipfs')` bundled with webpack/browserify/etc. * only `ipld-dag-pb`, `ipld-dag-cbor` and `ipld-raw` included * CDN bundle `<script src="https://unpkg.com/ipfs/dist/index.min.js"></script>` * all IPLD formats included Co-Authored-By: hugomrdias <mail@hugodias.me>
- Loading branch information
1 parent
5f62e99
commit 4376121
Showing
7 changed files
with
245 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
const mergeOptions = require('merge-options') | ||
|
||
module.exports = (blockService, options = {}) => { | ||
return mergeOptions.call( | ||
// ensure we have the defaults formats even if the user overrides `formats: []` | ||
{ concatArrays: true }, | ||
{ | ||
blockService: blockService, | ||
formats: [ | ||
require('ipld-dag-cbor'), | ||
require('ipld-dag-pb'), | ||
require('ipld-raw'), | ||
require('ipld-bitcoin'), | ||
require('ipld-ethereum').ethAccountSnapshot, | ||
require('ipld-ethereum').ethBlock, | ||
require('ipld-ethereum').ethBlockList, | ||
require('ipld-ethereum').ethStateTrie, | ||
require('ipld-ethereum').ethStorageTrie, | ||
require('ipld-ethereum').ethTx, | ||
require('ipld-ethereum').ethTxTrie, | ||
require('ipld-git'), | ||
require('ipld-zcash') | ||
] | ||
}, options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict' | ||
const mergeOptions = require('merge-options') | ||
const ipldDagCbor = require('ipld-dag-cbor') | ||
const ipldDagPb = require('ipld-dag-pb') | ||
const ipldRaw = require('ipld-raw') | ||
|
||
module.exports = (blockService, options = {}) => { | ||
return mergeOptions.call( | ||
// ensure we have the defaults formats even if the user overrides `formats: []` | ||
{ concatArrays: true }, | ||
{ | ||
blockService: blockService, | ||
formats: [ipldDagCbor, ipldDagPb, ipldRaw] | ||
}, options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict' | ||
const mergeOptions = require('merge-options') | ||
const ipldDagCbor = require('ipld-dag-cbor') | ||
const ipldDagPb = require('ipld-dag-pb') | ||
const ipldRaw = require('ipld-raw') | ||
|
||
// All known (non-default) IPLD formats | ||
const IpldFormats = { | ||
get 'bitcoin-block' () { | ||
return require('ipld-bitcoin') | ||
}, | ||
get 'eth-account-snapshot' () { | ||
return require('ipld-ethereum').ethAccountSnapshot | ||
}, | ||
get 'eth-block' () { | ||
return require('ipld-ethereum').ethBlock | ||
}, | ||
get 'eth-block-list' () { | ||
return require('ipld-ethereum').ethBlockList | ||
}, | ||
get 'eth-state-trie' () { | ||
return require('ipld-ethereum').ethStateTrie | ||
}, | ||
get 'eth-storage-trie' () { | ||
return require('ipld-ethereum').ethStorageTrie | ||
}, | ||
get 'eth-tx' () { | ||
return require('ipld-ethereum').ethTx | ||
}, | ||
get 'eth-tx-trie' () { | ||
return require('ipld-ethereum').ethTxTrie | ||
}, | ||
get 'git-raw' () { | ||
return require('ipld-git') | ||
}, | ||
get 'zcash-block' () { | ||
return require('ipld-zcash') | ||
} | ||
} | ||
|
||
module.exports = (blockService, options = {}, log) => { | ||
return mergeOptions.call( | ||
// ensure we have the defaults formats even if the user overrides `formats: []` | ||
{ concatArrays: true }, | ||
{ | ||
blockService: blockService, | ||
formats: [ipldDagCbor, ipldDagPb, ipldRaw], | ||
loadFormat: (codec, callback) => { | ||
log('Loading IPLD format', codec) | ||
if (IpldFormats[codec]) return callback(null, IpldFormats[codec]) | ||
callback(new Error(`Missing IPLD format "${codec}"`)) | ||
} | ||
}, options) | ||
} |