File tree 5 files changed +60
-7
lines changed
5 files changed +60
-7
lines changed Original file line number Diff line number Diff line change 4
4
"description" : " JS implementation of the IPFS UnixFS" ,
5
5
"scripts" : {
6
6
"reset" : " lerna run clean && rimraf packages/*/node_modules node_modules packages/*/package-lock.json package-lock.json" ,
7
+ "postinstall" : " lerna link" ,
7
8
"test" : " lerna run test" ,
8
9
"coverage" : " lerna run coverage" ,
9
10
"prepare" : " lerna run prepare" ,
Original file line number Diff line number Diff line change 9
9
"fs" : false
10
10
},
11
11
"scripts" : {
12
- "prepare" : " aegir build --no-bundle" ,
12
+ "prepare" : " aegir build --no-bundle --esm-tests " ,
13
13
"test" : " aegir test" ,
14
14
"build" : " aegir build --esm-tests" ,
15
15
"clean" : " rimraf ./dist" ,
33
33
"npm" : " >=7.0.0"
34
34
},
35
35
"homepage" : " https://github.com/ipfs/js-ipfs-unixfs#readme" ,
36
+ "publishConfig" : {
37
+ "directory" : " dist"
38
+ },
36
39
"devDependencies" : {
37
40
"@types/mocha" : " ^8.2.1" ,
38
41
"@types/sinon" : " ^10.0.0" ,
Original file line number Diff line number Diff line change 1
- /** @type { () => import('interface-blockstore').Blockstore } */
2
- // @ts -expect-error no types for this deep import
3
- import block from 'ipfs-unixfs-importer/test/helpers/block.js '
1
+ import errCode from 'err-code'
2
+ import { BlockstoreAdapter } from 'interface-blockstore'
3
+ import { base58btc } from 'multiformats/bases/base58 '
4
4
5
- export default block
5
+ /**
6
+ * @typedef {import('multiformats/cid').CID } CID
7
+ */
8
+
9
+ function createBlockApi ( ) {
10
+ class MockBlockstore extends BlockstoreAdapter {
11
+ constructor ( ) {
12
+ super ( )
13
+
14
+ /** @type {{[key: string]: Uint8Array} } */
15
+ this . _blocks = { }
16
+ }
17
+
18
+ /**
19
+ * @param {CID } cid
20
+ * @param {Uint8Array } block
21
+ * @param {any } [options]
22
+ */
23
+ async put ( cid , block , options = { } ) {
24
+ this . _blocks [ base58btc . encode ( cid . multihash . bytes ) ] = block
25
+ }
26
+
27
+ /**
28
+ * @param {CID } cid
29
+ * @param {any } [options]
30
+ */
31
+ async get ( cid , options = { } ) {
32
+ const bytes = this . _blocks [ base58btc . encode ( cid . multihash . bytes ) ]
33
+
34
+ if ( bytes === undefined ) {
35
+ throw errCode ( new Error ( `Could not find data for CID '${ cid } '` ) , 'ERR_NOT_FOUND' )
36
+ }
37
+
38
+ return bytes
39
+ }
40
+ }
41
+
42
+ /** @type {import('interface-blockstore').Blockstore } */
43
+ const bs = new MockBlockstore ( )
44
+
45
+ return bs
46
+ }
47
+
48
+ export default createBlockApi
Original file line number Diff line number Diff line change 9
9
"fs" : false
10
10
},
11
11
"scripts" : {
12
- "prepare" : " aegir build --no-bundle" ,
12
+ "prepare" : " aegir build --no-bundle --esm-tests " ,
13
13
"test" : " aegir test" ,
14
14
"build" : " aegir build --esm-tests" ,
15
15
"clean" : " rimraf ./dist" ,
33
33
"npm" : " >=7.0.0"
34
34
},
35
35
"homepage" : " https://github.com/ipfs/js-ipfs-unixfs#readme" ,
36
+ "publishConfig" : {
37
+ "directory" : " dist"
38
+ },
36
39
"devDependencies" : {
37
40
"@types/mocha" : " ^8.2.1" ,
38
41
"aegir" : " https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist" ,
Original file line number Diff line number Diff line change 9
9
"fs" : false
10
10
},
11
11
"scripts" : {
12
- "prepare" : " aegir build" ,
12
+ "prepare" : " aegir build --esm-tests " ,
13
13
"prepare:proto" : " pbjs -t static-module -w es6 -r ipfs-unixfs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/unixfs.js ./src/unixfs.proto" ,
14
14
"prepare:proto-types" : " pbts -o src/unixfs.d.ts src/unixfs.js" ,
15
15
"prepare:types" : " aegir build --no-bundle" ,
36
36
"npm" : " >=7.0.0"
37
37
},
38
38
"homepage" : " https://github.com/ipfs/js-ipfs-unixfs#readme" ,
39
+ "publishConfig" : {
40
+ "directory" : " dist"
41
+ },
39
42
"devDependencies" : {
40
43
"@types/mocha" : " ^8.2.1" ,
41
44
"aegir" : " https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist" ,
You can’t perform that action at this time.
0 commit comments