-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: remove default export, multiformats@7, full type check & gen
BREAKING CHANGE: * remove `default` export, see below * check, generate and publish full TypeScript types * use multiformats@7 and its non-default exports and updated types * export types based on latest multiformats structure * publish with "main" Prior to this change this module was imported as ```js import dagcbor from '@ipld/dag-cbor' ``` Now it is imported as ```js import * as dagcbor from `@ipld/dag-cbor' ```
- Loading branch information
Showing
9 changed files
with
164 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,66 @@ | ||
{ | ||
"name": "@ipld/dag-cbor", | ||
"version": "0.0.0-dev", | ||
"description": "JS implementation of dag-cbor", | ||
"description": "JS implementation of DAG-CBOR", | ||
"main": "index.js", | ||
"types": "./types/index.d.ts", | ||
"type": "module", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"lint": "standard", | ||
"lint": "standard *.js test/*.js", | ||
"build": "npm run build:js && npm run build:types", | ||
"build:js": "npm_config_yes=true npx ipjs@latest build --tests", | ||
"build:types": "tsc --build", | ||
"check": "tsc --build --noEmit --noErrorTruncation", | ||
"publish": "npm_config_yes=true npx ipjs@latest publish", | ||
"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js", | ||
"build:js": "ipjs build --tests --main && npm run build:copy", | ||
"build:copy": "cp -a tsconfig.json index.js dist/ && mkdir -p dist/test && cp test/*.js dist/test/", | ||
"build:types": "npm run build:copy && cd dist && tsc --build", | ||
"publish": "ipjs publish", | ||
"test:cjs": "npm run build:js && mocha dist/cjs/node-test/test-*.js && npm run test:cjs:browser", | ||
"test:node": "hundreds mocha test/test-*.js", | ||
"test:browser": "polendina --cleanup dist/cjs/node-test/test-*.js", | ||
"test": "npm run lint && npm run test:node && npm run test:cjs && npm run test:browser", | ||
"coverage": "c8 --reporter=html mocha test/test-*.js && npx st -d coverage -p 8080" | ||
"test:cjs:browser": "polendina --page --worker --serviceworker --cleanup dist/cjs/node-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:cjs && npm run test:ts", | ||
"coverage": "c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080" | ||
}, | ||
"exports": { | ||
"import": "./index.js" | ||
}, | ||
"license": "(Apache-2.0 AND MIT)", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ipld/js-dag-cbor.git" | ||
}, | ||
"keywords": [ | ||
"IPFS" | ||
"IPFS", | ||
"IPLD" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ipld/js-dag-cbor/issues" | ||
}, | ||
"homepage": "https://github.com/ipld/js-dag-cbor", | ||
"dependencies": { | ||
"cborg": "^1.1.2", | ||
"multiformats": "^4.6.1" | ||
"cborg": "^1.2.1", | ||
"multiformats": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.3.3", | ||
"chai": "^4.3.4", | ||
"hundreds": "^0.0.9", | ||
"ipld-garbage": "^2.0.0", | ||
"mocha": "^8.3.1", | ||
"ipjs": "^5.0.0", | ||
"ipld-garbage": "^3.0.0", | ||
"mocha": "^8.3.2", | ||
"polendina": "^1.1.0", | ||
"standard": "^16.0.3", | ||
"typescript": "^4.2.3" | ||
"typescript": "^4.2.4" | ||
}, | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
"types/*" | ||
], | ||
"types/*": [ | ||
"types/*" | ||
] | ||
} | ||
}, | ||
"author": "Mikeal Rogers <mikeal.rogers@gmail.com> (https://www.mikealrogers.com/)" | ||
} |
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,3 @@ | ||
node_modules | ||
src/main.js | ||
tsconfig.tsbuildinfo |
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,11 @@ | ||
{ | ||
"name": "ts-use", | ||
"private": true, | ||
"dependencies": { | ||
"@ipld/dag-cbor": "file:../../dist/", | ||
"multiformats": "file:../../node_modules/multiformats" | ||
}, | ||
"scripts": { | ||
"test": "npm install && npx -p typescript tsc && node src/main.js" | ||
} | ||
} |
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,45 @@ | ||
import { deepStrictEqual } from 'assert' | ||
|
||
import { BlockEncoder, BlockDecoder, BlockCodec } from 'multiformats/codecs/interface' | ||
import * as dagCbor from '@ipld/dag-cbor' | ||
|
||
const main = () => { | ||
// make sure we have a full CodecFeature | ||
useCodecFeature(dagCbor) | ||
} | ||
|
||
function useCodecFeature (codec: BlockCodec<0x71, any>) { | ||
// use only as a BlockEncoder | ||
useEncoder(codec) | ||
|
||
// use only as a BlockDecoder | ||
useDecoder(codec) | ||
|
||
// use as a full BlockCodec which does both BlockEncoder & BlockDecoder | ||
useBlockCodec(codec) | ||
} | ||
|
||
function useEncoder<Codec extends number> (encoder: BlockEncoder<Codec, string>) { | ||
deepStrictEqual(encoder.code, 0x71) | ||
deepStrictEqual(encoder.name, 'dag-cbor') | ||
deepStrictEqual(Array.from(encoder.encode('blip')), [100, 98, 108, 105, 112]) | ||
console.log('[TS] ✓ { encoder: BlockEncoder }') | ||
} | ||
|
||
function useDecoder<Codec extends number> (decoder: BlockDecoder<Codec, Uint8Array>) { | ||
deepStrictEqual(decoder.code, 0x71) | ||
deepStrictEqual(decoder.decode(Uint8Array.from([100, 98, 108, 105, 112])), 'blip') | ||
console.log('[TS] ✓ { decoder: BlockDecoder }') | ||
} | ||
|
||
function useBlockCodec<Codec extends number> (blockCodec: BlockCodec<Codec, string>) { | ||
deepStrictEqual(blockCodec.code, 0x71) | ||
deepStrictEqual(blockCodec.name, 'dag-cbor') | ||
deepStrictEqual(Array.from(blockCodec.encode('blip')), [100, 98, 108, 105, 112]) | ||
deepStrictEqual(blockCodec.decode(Uint8Array.from([100, 98, 108, 105, 112])), 'blip') | ||
console.log('[TS] ✓ {}:BlockCodec') | ||
} | ||
|
||
main() | ||
|
||
export default main |
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,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"noImplicitAny": true, | ||
"skipLibCheck": true, | ||
"incremental": true | ||
} | ||
} |
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