├── .eslintrc ├── .github └── workflows │ └── typecheck.yml ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── package.json ├── src └── index.js ├── test └── index.spec.js └── tsconfig.json /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "ipfs" 3 | } 4 | -------------------------------------------------------------------------------- /.github/workflows/typecheck.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | - main 6 | - default 7 | pull_request: 8 | branches: 9 | - '**' 10 | 11 | name: Typecheck 12 | jobs: 13 | check: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | node-version: [12.x] 18 | steps: 19 | - uses: actions/checkout@v1 20 | - name: Use Node.js ${{ matrix.node-version }} 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: ${{ matrix.node-version }} 24 | - name: Install dependencies 25 | run: npm install 26 | - name: Typecheck 27 | uses: gozala/typescript-error-reporter-action@v1.0.4 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | yarn.lock 3 | test/repo-just-for-test* 4 | test/test-repo-for-* 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | 10 | # Runtime data 11 | pids 12 | *.pid 13 | *.seed 14 | 15 | # Directory for instrumented libs generated by jscoverage/JSCover 16 | lib-cov 17 | 18 | # Coverage directory used by tools like istanbul 19 | coverage 20 | 21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 22 | .grunt 23 | 24 | # node-waf configuration 25 | .lock-wscript 26 | 27 | # Compiled binary addons (http://nodejs.org/api/addons.html) 28 | build/Release 29 | 30 | # Dependency directory 31 | node_modules 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | dist 40 | docs 41 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # node-waf configuration 23 | .lock-wscript 24 | 25 | # Compiled binary addons (http://nodejs.org/api/addons.html) 26 | build/Release 27 | 28 | # Dependency directory 29 | node_modules 30 | 31 | # Optional npm cache directory 32 | .npm 33 | 34 | # Optional REPL history 35 | .node_repl_history 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | dist: bionic 3 | cache: npm 4 | stages: 5 | - check 6 | - test 7 | - cov 8 | 9 | branches: 10 | only: 11 | - master 12 | - /^release\/.*$/ 13 | 14 | node_js: 15 | - 'lts/*' 16 | - 'node' 17 | 18 | os: 19 | - linux 20 | - osx 21 | - windows 22 | 23 | before_install: 24 | # modules with pre-built binaries may not have deployed versions for bleeding-edge node so this lets us fall back to building from source 25 | - npm install -g @mapbox/node-pre-gyp 26 | 27 | script: npx nyc -s npm run test:node -- --bail 28 | after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov 29 | 30 | jobs: 31 | include: 32 | - stage: check 33 | script: 34 | - npx aegir dep-check 35 | - npm run lint 36 | 37 | - stage: test 38 | name: chrome 39 | addons: 40 | chrome: stable 41 | script: 42 | - npx aegir test -t browser -t webworker 43 | 44 | - stage: test 45 | name: firefox 46 | addons: 47 | firefox: latest 48 | script: npx aegir test -t browser -t webworker -- --browser firefox 49 | 50 | notifications: 51 | email: false 52 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## [0.11.1](https://github.com/ipld/js-ipld-block/compare/v0.11.0...v0.11.1) (2021-03-05) 3 | 4 | 5 | ### Bug Fixes 6 | 7 | * update type export ([889ac77](https://github.com/ipld/js-ipld-block/commit/889ac77)) 8 | 9 | 10 | 11 | 12 | # [0.11.0](https://github.com/ipld/js-ipld-block/compare/v0.10.1...v0.11.0) (2020-10-21) 13 | 14 | 15 | ### Bug Fixes 16 | 17 | * account error msg diff betwenn browsers ([85bef56](https://github.com/ipld/js-ipld-block/commit/85bef56)) 18 | * change deprecation to cover 0.11 ([36a4b61](https://github.com/ipld/js-ipld-block/commit/36a4b61)) 19 | * type mapping dir ([ddd1843](https://github.com/ipld/js-ipld-block/commit/ddd1843)) 20 | 21 | 22 | ### Features 23 | 24 | * add typedef generation ([e31d46b](https://github.com/ipld/js-ipld-block/commit/e31d46b)) 25 | 26 | 27 | 28 | 29 | ## [0.10.1](https://github.com/ipld/js-ipld-block/compare/v0.10.0...v0.10.1) (2020-09-01) 30 | 31 | 32 | 33 | 34 | # [0.10.0](https://github.com/ipld/js-ipld-block/compare/v0.9.2...v0.10.0) (2020-08-04) 35 | 36 | 37 | ### Bug Fixes 38 | 39 | * replace node buffers with uint8arrays ([0696e4d](https://github.com/ipld/js-ipld-block/commit/0696e4d)) 40 | 41 | 42 | ### BREAKING CHANGES 43 | 44 | * - The `.data` property used to be a Buffer, now it is a Uint8Array 45 | 46 | 47 | 48 | 49 | ## [0.9.2](https://github.com/ipld/js-ipld-block/compare/v0.9.1...v0.9.2) (2020-06-12) 50 | 51 | 52 | ### Features 53 | 54 | * add Uint8Array support ([418eb5f](https://github.com/ipld/js-ipld-block/commit/418eb5f)) 55 | 56 | 57 | 58 | 59 | ## [0.9.1](https://github.com/ipld/js-ipld-block/compare/v0.9.0...v0.9.1) (2020-04-01) 60 | 61 | 62 | ### Bug Fixes 63 | 64 | * add buffer ([b4e748c](https://github.com/ipld/js-ipld-block/commit/b4e748c)) 65 | 66 | 67 | 68 | 69 | # [0.9.0](https://github.com/ipld/js-ipld-block/compare/v0.8.0...v0.9.0) (2019-05-09) 70 | 71 | 72 | ### Features 73 | 74 | * this module is now named `ipld-block` ([5a3bbde](https://github.com/ipld/js-ipld-block/commit/5a3bbde)) 75 | 76 | 77 | ### BREAKING CHANGES 78 | 79 | * The symbol for comparing blocks changed 80 | 81 | This means that if you are a user of this module, updating to this version 82 | is also a breaking change for your module. Don't forgot to make the corresponding 83 | version bump on your next release. 84 | 85 | 86 | 87 | 88 | # [0.8.0](https://github.com/ipfs/js-ipfs-block/compare/v0.7.1...v0.8.0) (2018-10-26) 89 | 90 | 91 | 92 | 93 | ## [0.7.1](https://github.com/ipfs/js-ipfs-block/compare/v0.7.0...v0.7.1) (2018-04-09) 94 | 95 | 96 | 97 | 98 | # [0.7.0](https://github.com/ipfs/js-ipfs-block/compare/v0.6.1...v0.7.0) (2018-04-09) 99 | 100 | 101 | ### Features 102 | 103 | * use class-is module for type checks ([958cd09](https://github.com/ipfs/js-ipfs-block/commit/958cd09)) 104 | 105 | 106 | 107 | 108 | ## [0.6.1](https://github.com/ipfs/js-ipfs-block/compare/v0.6.0...v0.6.1) (2017-11-06) 109 | 110 | 111 | ### Bug Fixes 112 | 113 | * **package:** update cids to version 0.5.0 ([#33](https://github.com/ipfs/js-ipfs-block/issues/33)) ([f0101f0](https://github.com/ipfs/js-ipfs-block/commit/f0101f0)) 114 | 115 | 116 | ### Features 117 | 118 | * windows support ([7e2623b](https://github.com/ipfs/js-ipfs-block/commit/7e2623b)) 119 | 120 | 121 | 122 | 123 | # [0.6.0](https://github.com/ipfs/js-ipfs-block/compare/v0.5.5...v0.6.0) (2017-03-20) 124 | 125 | 126 | ### Features 127 | 128 | * simplify block to only be data and cid ([#31](https://github.com/ipfs/js-ipfs-block/issues/31)) ([0581c27](https://github.com/ipfs/js-ipfs-block/commit/0581c27)) 129 | 130 | 131 | 132 | 133 | ## [0.5.5](https://github.com/ipfs/js-ipfs-block/compare/v0.5.4...v0.5.5) (2017-02-09) 134 | 135 | 136 | ### Bug Fixes 137 | 138 | * **package:** update multihashing-async to version 0.4.0 ([#27](https://github.com/ipfs/js-ipfs-block/issues/27)) ([18a7d28](https://github.com/ipfs/js-ipfs-block/commit/18a7d28)) 139 | 140 | 141 | 142 | 143 | ## [0.5.4](https://github.com/ipfs/js-ipfs-block/compare/v0.5.3...v0.5.4) (2016-12-22) 144 | 145 | 146 | ### Bug Fixes 147 | 148 | * **deps:** add async to dependencies ([5f75307](https://github.com/ipfs/js-ipfs-block/commit/5f75307)) 149 | 150 | 151 | 152 | 153 | ## [0.5.3](https://github.com/ipfs/js-ipfs-block/compare/v0.5.2...v0.5.3) (2016-12-11) 154 | 155 | 156 | ### Bug Fixes 157 | 158 | * Buffer check ([185e8f6](https://github.com/ipfs/js-ipfs-block/commit/185e8f6)) 159 | 160 | 161 | 162 | 163 | ## [0.5.2](https://github.com/ipfs/js-ipfs-block/compare/v0.5.1...v0.5.2) (2016-12-11) 164 | 165 | 166 | ### Features 167 | 168 | * convert String values to buffers to avoid strange situations in the browser ([#19](https://github.com/ipfs/js-ipfs-block/issues/19)) ([794dade](https://github.com/ipfs/js-ipfs-block/commit/794dade)) 169 | 170 | 171 | 172 | 173 | ## [0.5.1](https://github.com/ipfs/js-ipfs-block/compare/v0.5.0...v0.5.1) (2016-12-01) 174 | 175 | 176 | 177 | 178 | # [0.5.0](https://github.com/ipfs/js-ipfs-block/compare/v0.4.0...v0.5.0) (2016-11-03) 179 | 180 | 181 | 182 | 183 | # [0.4.0](https://github.com/ipfs/js-ipfs-block/compare/v0.3.0...v0.4.0) (2016-10-26) 184 | 185 | 186 | ### Features 187 | 188 | * support multiple hash functions ([e2b9da4](https://github.com/ipfs/js-ipfs-block/commit/e2b9da4)) 189 | 190 | 191 | 192 | 193 | # [0.3.0](https://github.com/ipfs/js-ipfs-block/compare/v0.2.2...v0.3.0) (2016-05-02) 194 | 195 | 196 | 197 | 198 | ## [0.2.2](https://github.com/ipfs/js-ipfs-block/compare/v0.2.1...v0.2.2) (2016-04-30) 199 | 200 | 201 | 202 | 203 | ## [0.2.1](https://github.com/ipfs/js-ipfs-block/compare/v0.2.0...v0.2.1) (2016-04-30) 204 | 205 | 206 | 207 | 208 | # 0.2.0 (2016-04-26) 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 IPFS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IPLD Block JavaScript Implementation 2 | 3 | **This project is no longer maintained and has been archived. See https://github.com/multiformats/js-multiformats or https://ipld.io for details on the latest methods for interacting with IPLD data in JavaScript.** 4 | 5 | [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) 6 | [![](https://img.shields.io/badge/project-IPLD-blue.svg?style=flat-square)](http://ipld.io/) 7 | [![](https://img.shields.io/badge/freenode-%23ipld-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipld) 8 | [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) 9 | [![Travis CI](https://flat.badgen.net/travis/ipld/js-ipld-block)](https://travis-ci.com/ipld/js-ipld-block) 10 | [![Coverage Status](https://coveralls.io/repos/github/ipld/js-ipld-block/badge.svg?branch=master)](https://coveralls.io/github/ipld/js-ipld-block?branch=master) 11 | [![Dependency Status](https://david-dm.org/ipld/js-ipld-block.svg?style=flat-square)](https://david-dm.org/ipld/js-ipld-block) 12 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) 13 | ![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square) 14 | ![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square) 15 | 16 | > [IPLD][ipld] implementation of the Block data structure in JavaScript. 17 | 18 | **Block** - A block is a blob of binary data combined with a [CID]. 19 | 20 | ## Lead Maintainer 21 | 22 | [Volker Mische](https://github.com/vmx) 23 | 24 | ## Table of Contents 25 | 26 | - [IPLD Block JavaScript Implementation](#ipld-block-javascript-implementation) 27 | - [Lead Maintainer](#lead-maintainer) 28 | - [Table of Contents](#table-of-contents) 29 | - [Install](#install) 30 | - [npm](#npm) 31 | - [Usage](#usage) 32 | - [Node.js](#nodejs) 33 | - [Example](#example) 34 | - [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers) 35 | - [Browser: ` 89 | 90 | 91 | ``` 92 | 93 | ## API 94 | 95 | ```js 96 | const Block = require('ipld-block') 97 | ``` 98 | 99 | ### Block 100 | 101 | #### `new Block(data, cid)` 102 | 103 | - `data: Uint8Array` 104 | 105 | Creates a new block with raw data `data`. 106 | 107 | #### `block.data` 108 | 109 | The raw data of the block. Its format matches whatever was provided in its constructor. 110 | 111 | #### `block.cid` 112 | 113 | The cid of the block. 114 | 115 | [ipld]: https://ipld.io/ 116 | [multihash]: https://github.com/multiformats/js-multihash 117 | [CID]: https://github.com/multiformats/js-cid 118 | 119 | ## Contribute 120 | 121 | Feel free to join in. All welcome. Open an [issue](https://github.com/ipld/js-ipld-block/issues)! 122 | 123 | This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). 124 | 125 | [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md) 126 | 127 | ## License 128 | 129 | [MIT](LICENSE) 130 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ipld-block", 3 | "version": "0.11.1", 4 | "description": "JavaScript Implementation of IPLD Block", 5 | "leadMaintainer": "Volker Mische ", 6 | "main": "src/index.js", 7 | "types": "dist/src/index.d.ts", 8 | "scripts": { 9 | "lint": "aegir lint", 10 | "check": "tsc --noEmit --noErrorTruncation", 11 | "test": "aegir test", 12 | "test:node": "aegir test --target node", 13 | "test:browser": "aegir test --target browser", 14 | "release": "aegir release --docs", 15 | "release-minor": "aegir release --type minor --docs", 16 | "release-major": "aegir release --type major --docs", 17 | "coverage": "aegir coverage", 18 | "coverage-publish": "aegir coverage --provider coveralls", 19 | "docs": "aegir docs", 20 | "prepare": "aegir build --no-bundle", 21 | "prepublishOnly": "aegir build" 22 | }, 23 | "pre-push": [ 24 | "lint", 25 | "test" 26 | ], 27 | "repository": { 28 | "type": "git", 29 | "url": "git+https://github.com/ipld/js-ipld-block.git" 30 | }, 31 | "keywords": [ 32 | "IPLD" 33 | ], 34 | "license": "MIT", 35 | "bugs": { 36 | "url": "https://github.com/ipld/js-ipld-block/issues" 37 | }, 38 | "homepage": "https://github.com/ipld/js-ipld-block#readme", 39 | "devDependencies": { 40 | "aegir": "^31.0.4", 41 | "uint8arrays": "^2.1.3" 42 | }, 43 | "dependencies": { 44 | "cids": "^1.0.0" 45 | }, 46 | "engines": { 47 | "node": ">=6.0.0", 48 | "npm": ">=3.0.0" 49 | }, 50 | "contributors": [ 51 | "David Dias ", 52 | "Volker Mische ", 53 | "Friedel Ziegelmayer ", 54 | "Irakli Gozalishvili ", 55 | "achingbrain ", 56 | "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ ", 57 | "Alan Shaw ", 58 | "Charlie ", 59 | "Diogo Silva ", 60 | "Hugo Dias ", 61 | "Mikeal Rogers ", 62 | "Richard Littauer ", 63 | "Richard Schneider ", 64 | "Xmader " 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const CID = require('cids') 4 | 5 | const { version } = require('../package.json') 6 | const blockSymbol = Symbol.for('@ipld/js-ipld-block/block') 7 | const readonly = { writable: false, configurable: false, enumerable: true } 8 | 9 | /** 10 | * Represents an immutable block of data that is uniquely referenced with a cid. 11 | * 12 | * @example 13 | * const block = new Block(Uint8Array.from([0, 1, 2, 3]), new CID('...')) 14 | */ 15 | class Block { 16 | /** 17 | * @param {Uint8Array} data - The data to be stored in the block as a Uint8Array. 18 | * @param {CID} cid - The cid of the data 19 | */ 20 | constructor (data, cid) { 21 | if (!data || !(data instanceof Uint8Array)) { 22 | throw new Error('first argument must be a Uint8Array') 23 | } 24 | 25 | if (!cid || !CID.isCID(cid)) { 26 | throw new Error('second argument must be a CID') 27 | } 28 | 29 | this.data = data 30 | this.cid = cid 31 | 32 | Object.defineProperties(this, { 33 | data: readonly, 34 | cid: readonly 35 | }) 36 | } 37 | 38 | /** 39 | * The data of this block. 40 | * 41 | * @deprecated 42 | * @type {Uint8Array} 43 | */ 44 | get _data () { 45 | deprecateData() 46 | return this.data 47 | } 48 | 49 | /** 50 | * The cid of the data this block represents. 51 | * 52 | * @deprecated 53 | * @type {CID} 54 | */ 55 | get _cid () { 56 | deprecateCID() 57 | return this.cid 58 | } 59 | 60 | get [Symbol.toStringTag] () { 61 | return 'Block' 62 | } 63 | 64 | get [blockSymbol] () { 65 | return true 66 | } 67 | 68 | /** 69 | * Check if the given value is a Block. 70 | * 71 | * @param {any} other 72 | * @returns {other is Block} 73 | */ 74 | static isBlock (other) { 75 | return Boolean(other && other[blockSymbol]) 76 | } 77 | } 78 | 79 | /** 80 | * @param {RegExp} range 81 | * @param {string} message 82 | * @returns {() => void} 83 | */ 84 | const deprecate = (range, message) => { 85 | let warned = false 86 | return () => { 87 | if (range.test(version)) { 88 | if (!warned) { 89 | warned = true 90 | // eslint-disable-next-line no-console 91 | console.warn(message) 92 | } 93 | } else { 94 | throw new Error(message) 95 | } 96 | } 97 | } 98 | 99 | const deprecateCID = deprecate(/^0\.10|^0\.11/, 'block._cid is deprecated and will be removed in 0.12 release. Please use block.cid instead') 100 | const deprecateData = deprecate(/^0\.10|^0.11/, 'block._data is deprecated and will be removed in 0.12 release. Please use block.data instead') 101 | 102 | module.exports = Block 103 | -------------------------------------------------------------------------------- /test/index.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | 'use strict' 3 | 4 | const { expect } = require('aegir/utils/chai') 5 | const CID = require('cids') 6 | const uint8ArrayFromString = require('uint8arrays/from-string') 7 | 8 | const Block = require('../src') 9 | 10 | describe('block', () => { 11 | it('create throws', () => { 12 | expect( 13 | // @ts-expect-error arg type wrong 14 | () => new Block('string') 15 | ).to.throw() 16 | 17 | expect( 18 | // @ts-expect-error arg type wrong 19 | () => new Block(uint8ArrayFromString('hello'), 'cid') 20 | ).to.throw() 21 | 22 | expect( 23 | // @ts-expect-error arg type wrong 24 | () => new Block('hello', new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')) 25 | ).to.throw() 26 | }) 27 | 28 | it('create', () => { 29 | const cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n') 30 | const data = uint8ArrayFromString('hello') 31 | const b = new Block(data, cid) 32 | 33 | expect(Block.isBlock(b)).to.eql(true) 34 | expect(b.toString()).to.eql('[object Block]') 35 | expect(b.data).to.eql(data) 36 | expect(b.cid).to.eql(cid) 37 | expect(b._data).to.eql(data) 38 | expect(b._data).to.eql(data) 39 | expect(b._cid).to.eql(cid) 40 | expect(b._cid).to.eql(cid) 41 | }) 42 | 43 | it('block stays immutable', () => { 44 | const b = new Block(uint8ArrayFromString('hello'), new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')) 45 | 46 | expect( 47 | // @ts-expect-error arg type wrong 48 | () => { b.data = 'fail' } 49 | ).to.throw( 50 | /read.only/ 51 | ) 52 | 53 | expect( 54 | // @ts-expect-error arg type wrong 55 | () => { b.cid = 'fail' } 56 | ).to.throw( 57 | /read.only/ 58 | ) 59 | }) 60 | }) 61 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "test", 8 | "src", 9 | "package.json" 10 | ] 11 | } 12 | --------------------------------------------------------------------------------