@ipld/dag-pb
Advanced tools
Comparing version 2.1.18 to 3.0.0
144
package.json
{ | ||
"name": "@ipld/dag-pb", | ||
"version": "2.1.18", | ||
"version": "3.0.0", | ||
"description": "JS implementation of DAG-PB", | ||
"main": "./cjs/src/index.js", | ||
"types": "./types/src/index.d.ts", | ||
"scripts": { | ||
"lint": "standard", | ||
"build": "npm run build:js && npm run build:types", | ||
"build:js": "ipjs build --tests --main && npm run build:copy", | ||
"build:copy": "cp -a tsconfig.json src *.js dist/ && mkdir -p dist/test && cp test/*.js dist/test/", | ||
"build:types": "npm run build:copy && cd dist && tsc --build", | ||
"test:cjs": "npm run build:js && mocha dist/cjs/node-test/test-*.js && npm run test:cjs:browser", | ||
"test:esm": "npm run build:js && mocha dist/esm/node-test/test-*.js && npm run test:esm:browser", | ||
"test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/test-*.js", | ||
"test:cjs:browser": "polendina --page --worker --serviceworker --cleanup dist/cjs/browser-test/test-*.js", | ||
"test:esm:browser": "polendina --page --worker --serviceworker --cleanup dist/esm/browser-test/test-*.js", | ||
"test:ts": "npm run build:types && npm run test --prefix test/ts-use", | ||
"test": "npm run lint && npm run test:node && npm run test:esm && npm run test:ts", | ||
"test:ci": "npm run lint && npm run test:node && npm run test:esm && npm run test:cjs && npm run test:ts", | ||
"coverage": "c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080" | ||
}, | ||
"keywords": [ | ||
"ipfs", | ||
"ipld", | ||
"multiformats" | ||
], | ||
"author": "Rod <rod@vagg.org> (http://r.va.gg/)", | ||
"license": "(Apache-2.0 AND MIT)", | ||
"exports": { | ||
"browser": "./esm/src/index.js", | ||
"require": "./cjs/src/index.js", | ||
"import": "./esm/src/index.js" | ||
}, | ||
"dependencies": { | ||
"multiformats": "^9.5.4" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.3.0", | ||
"@types/mocha": "^9.0.0", | ||
"c8": "^7.10.0", | ||
"chai": "^4.3.4", | ||
"chai-subset": "^1.6.0", | ||
"ipjs": "^5.2.0", | ||
"mocha": "^10.0.0", | ||
"polendina": "~3.1.0", | ||
"standard": "^17.0.0", | ||
"typescript": "~4.8.2" | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"dist", | ||
"test/ts-use/src/main.js" | ||
] | ||
}, | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"license": "Apache-2.0 OR MIT", | ||
"homepage": "https://github.com/ipld/js-dag-pb#readme", | ||
"repository": { | ||
@@ -66,13 +15,51 @@ "type": "git", | ||
}, | ||
"homepage": "https://github.com/ipld/js-dag-pb#readme", | ||
"keywords": [ | ||
"ipfs", | ||
"ipld", | ||
"multiformats" | ||
], | ||
"engines": { | ||
"node": ">=16.0.0", | ||
"npm": ">=7.0.0" | ||
}, | ||
"type": "module", | ||
"types": "./dist/src/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
"types/*" | ||
"*", | ||
"dist/*", | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
], | ||
"types/*": [ | ||
"types/*" | ||
"src/*": [ | ||
"*", | ||
"dist/*", | ||
"dist/src/*", | ||
"dist/src/*/index" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"!dist/test", | ||
"!**/*.tsbuildinfo" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/src/index.d.ts", | ||
"import": "./src/index.js" | ||
} | ||
}, | ||
"eslintConfig": { | ||
"extends": "ipfs", | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"ignorePatterns": [ | ||
"dist", | ||
"test/ts-use" | ||
] | ||
}, | ||
"release": { | ||
@@ -105,11 +92,11 @@ "branches": [ | ||
{ | ||
"type": "chore", | ||
"type": "docs", | ||
"release": "patch" | ||
}, | ||
{ | ||
"type": "docs", | ||
"type": "test", | ||
"release": "patch" | ||
}, | ||
{ | ||
"type": "test", | ||
"type": "deps", | ||
"release": "patch" | ||
@@ -144,5 +131,9 @@ }, | ||
"type": "docs", | ||
"section": "Trivial Changes" | ||
"section": "Documentation" | ||
}, | ||
{ | ||
"type": "deps", | ||
"section": "Dependencies" | ||
}, | ||
{ | ||
"type": "test", | ||
@@ -156,8 +147,3 @@ "section": "Tests" | ||
"@semantic-release/changelog", | ||
[ | ||
"@semantic-release/npm", | ||
{ | ||
"pkgRoot": "dist" | ||
} | ||
], | ||
"@semantic-release/npm", | ||
"@semantic-release/github", | ||
@@ -167,3 +153,23 @@ "@semantic-release/git" | ||
}, | ||
"browser": "./cjs/src/index.js" | ||
"scripts": { | ||
"clean": "aegir clean", | ||
"lint": "aegir lint", | ||
"build": "aegir build", | ||
"release": "aegir release", | ||
"test": "aegir lint && aegir test", | ||
"test:ts": "npm run test --prefix test/ts-use", | ||
"test:node": "aegir test -t node --cov", | ||
"test:chrome": "aegir test -t browser --cov", | ||
"test:chrome-webworker": "aegir test -t webworker", | ||
"test:firefox": "aegir test -t browser -- --browser firefox", | ||
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox", | ||
"test:electron-main": "aegir test -t electron-main", | ||
"dep-check": "aegir dep-check" | ||
}, | ||
"dependencies": { | ||
"multiformats": "^10.0.2" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^37.5.2" | ||
} | ||
} |
@@ -1,3 +0,27 @@ | ||
# @ipld/dag-pb | ||
# @ipld/dag-pb <!-- omit in toc --> | ||
[![codecov](https://img.shields.io/codecov/c/github/ipld/js-dag-pb.svg?style=flat-square)](https://codecov.io/gh/ipld/js-dag-pb) | ||
[![CI](https://img.shields.io/github/workflow/status/ipld/js-dag-pb/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipld/js-dag-pb/actions/workflows/js-test-and-release.yml) | ||
> JS implementation of DAG-PB | ||
## Table of contents <!-- omit in toc --> | ||
- [Install](#install) | ||
- [Overview](#overview) | ||
- [Example](#example) | ||
- [Usage](#usage) | ||
- [`prepare()`](#prepare) | ||
- [`createNode()` & `createLink()`](#createnode--createlink) | ||
- [License](#license) | ||
- [Contribute](#contribute) | ||
## Install | ||
```console | ||
$ npm i @ipld/dag-pb | ||
``` | ||
## Overview | ||
An implementation of the [DAG-PB spec](https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-pb.md) for JavaScript designed for use with [multiformats](https://github.com/multiformats/js-multiformats) or via the higher-level `Block` abstraction in [@ipld/block](https://github.com/ipld/js-block). | ||
@@ -45,3 +69,3 @@ | ||
The DAG-PB encoding is very strict about the Data Model forms that are passed in. The objects _must_ exactly resemble what they would if they were to undergo a round-trip of encode & decode. Therefore, extraneous or mistyped properties are not acceptable and will be rejected. See the [DAG-PB spec](https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-pb.md) for full details of the acceptable schema and additional constraints. | ||
The DAG-PB encoding is very strict about the Data Model forms that are passed in. The objects *must* exactly resemble what they would if they were to undergo a round-trip of encode & decode. Therefore, extraneous or mistyped properties are not acceptable and will be rejected. See the [DAG-PB spec](https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-pb.md) for full details of the acceptable schema and additional constraints. | ||
@@ -62,9 +86,9 @@ Due to this strictness, a `prepare()` function is made available which simplifies construction and allows for more flexible input forms. Prior to encoding objects, call `prepare()` to receive a new object that strictly conforms to the schema. | ||
* Extraneous properties are omitted | ||
* String values for `Data` are converted | ||
* Strings are converted to `{ Data: bytes }` (as are `Uint8Array`s) | ||
* Multiple ways of finding CIDs in the `Links` array are attempted, including interpreting the whole link element as a CID, reading a `Uint8Array` as a CID | ||
* Ensuring that properties are of the correct type (link `Name` is a `string` and `Tsize` is a `number`) | ||
* `Links` array is always present, even if empty | ||
* `Links` array is properly sorted | ||
- Extraneous properties are omitted | ||
- String values for `Data` are converted | ||
- Strings are converted to `{ Data: bytes }` (as are `Uint8Array`s) | ||
- Multiple ways of finding CIDs in the `Links` array are attempted, including interpreting the whole link element as a CID, reading a `Uint8Array` as a CID | ||
- Ensuring that properties are of the correct type (link `Name` is a `string` and `Tsize` is a `number`) | ||
- `Links` array is always present, even if empty | ||
- `Links` array is properly sorted | ||
@@ -75,4 +99,4 @@ ## `createNode()` & `createLink()` | ||
* `createNode(data: Uint8Array, links: PBLink[]|void): PBNode`: create a correctly formed `PBNode` object from a `Uint8Array` and an optional array of correctly formed `PBLink` objects. The returned object will be suitable for passing to `encode()` and using `prepare()` on it should result in a noop. | ||
* `createLink(name: string, size: number, cid: CID): PBLink`: create a correctly formed `PBLink` object from a name, size and CID. The returned object will be suitable for attaching to a `PBNode`'s `Links` array, or in an array for the second argument to `createNode()`. | ||
- `createNode(data: Uint8Array, links: PBLink[]|void): PBNode`: create a correctly formed `PBNode` object from a `Uint8Array` and an optional array of correctly formed `PBLink` objects. The returned object will be suitable for passing to `encode()` and using `prepare()` on it should result in a noop. | ||
- `createLink(name: string, size: number, cid: CID): PBLink`: create a correctly formed `PBLink` object from a name, size and CID. The returned object will be suitable for attaching to a `PBNode`'s `Links` array, or in an array for the second argument to `createNode()`. | ||
@@ -105,23 +129,21 @@ ```js | ||
``` | ||
{ | ||
Data: Uint8Array(5) [ 0, 1, 2, 3, 4 ], | ||
Links: [ | ||
{ | ||
Hash: CID(QmWDtUQj38YLW8v3q4A6LwPn4vYKEbuKWpgSm6bjKW6Xfe), | ||
Name: 'link1', | ||
Tsize: 100 | ||
}, | ||
{ | ||
Hash: CID(bafyreifepiu23okq5zuyvyhsoiazv2icw2van3s7ko6d3ixl5jx2yj2yhu), | ||
Name: 'link2', | ||
Tsize: 200 | ||
Data: Uint8Array(5) [ 0, 1, 2, 3, 4 ], | ||
Links: [ | ||
{ | ||
Hash: CID(QmWDtUQj38YLW8v3q4A6LwPn4vYKEbuKWpgSm6bjKW6Xfe), | ||
Name: 'link1', | ||
Tsize: 100 | ||
}, | ||
{ | ||
Hash: CID(bafyreifepiu23okq5zuyvyhsoiazv2icw2van3s7ko6d3ixl5jx2yj2yhu), | ||
Name: 'link2', | ||
Tsize: 200 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
CID(bafybeihsp53wkzsaif76mjv564cawzqyjwianosamlvf6sht2m25ttyxiy) | ||
Encoded: 122d0a2212207521fe19c374a97759226dc5c0c8e674e73950e81b211f7dd3b6b30883a08a511205 | ||
6c696e6b31186412300a2401711220a47a29adb950ee698ae0f272019ae902b6aa06ee5f53bc3da2 | ||
ebea6fac27583d12056c696e6b3218c8010a050001020304 | ||
``` | ||
CID(bafybeihsp53wkzsaif76mjv564cawzqyjwianosamlvf6sht2m25ttyxiy) | ||
Encoded: 122d0a2212207521fe19c374a97759226dc5c0c8e674e73950e81b211f7dd3b6b30883a08a511205 | ||
6c696e6b31186412300a2401711220a47a29adb950ee698ae0f272019ae902b6aa06ee5f53bc3da2 | ||
ebea6fac27583d12056c696e6b3218c8010a050001020304 | ||
@@ -132,7 +154,7 @@ ## License | ||
* Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0) | ||
* MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT) | ||
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>) | ||
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>) | ||
### Contribution | ||
## Contribute | ||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. |
@@ -1,2 +0,2 @@ | ||
import { CID } from 'multiformats/cid' | ||
import type { CID } from 'multiformats/cid' | ||
@@ -9,4 +9,4 @@ /* | ||
export interface PBLink { | ||
Name?: string, | ||
Tsize?: number, | ||
Name?: string | ||
Tsize?: number | ||
Hash: CID | ||
@@ -16,3 +16,3 @@ } | ||
export interface PBNode { | ||
Data?: Uint8Array, | ||
Data?: Uint8Array | ||
Links: PBLink[] | ||
@@ -27,4 +27,4 @@ } | ||
export interface RawPBLink { | ||
Name: string, | ||
Tsize: number, | ||
Name: string | ||
Tsize: number | ||
Hash: Uint8Array | ||
@@ -34,5 +34,4 @@ } | ||
export interface RawPBNode { | ||
Data: Uint8Array, | ||
Data: Uint8Array | ||
Links: RawPBLink[] | ||
} | ||
@@ -100,3 +100,3 @@ const textDecoder = new TextDecoder() | ||
;[link.Hash, index] = decodeBytes(bytes, index) | ||
[link.Hash, index] = decodeBytes(bytes, index) | ||
} else if (fieldNum === 2) { | ||
@@ -124,3 +124,3 @@ if (link.Name !== undefined) { | ||
;[link.Tsize, index] = decodeVarint(bytes, index) | ||
[link.Tsize, index] = decodeVarint(bytes, index) | ||
} else { | ||
@@ -165,3 +165,3 @@ throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${fieldNum}`) | ||
;[data, index] = decodeBytes(bytes, index) | ||
[data, index] = decodeBytes(bytes, index) | ||
if (links) { | ||
@@ -168,0 +168,0 @@ linksBeforeData = true |
@@ -115,3 +115,3 @@ const textEncoder = new TextEncoder() | ||
* @param {RawPBNode} node | ||
* @returns {number} | ||
* @returns {number} | ||
*/ | ||
@@ -118,0 +118,0 @@ function sizeNode (node) { |
@@ -80,3 +80,3 @@ import { CID } from 'multiformats/cid' | ||
} | ||
} catch (e) { | ||
} catch (/** @type {any} */ e) { | ||
throw new TypeError(`Invalid DAG-PB form: ${e.message}`) | ||
@@ -83,0 +83,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
1
156
Yes
50694
19
80
800
+ Addedmultiformats@10.0.3(transitive)
- Removedmultiformats@9.9.0(transitive)
Updatedmultiformats@^10.0.2