Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad publish bump #73

Merged
merged 9 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ package-lock.json
node_modules
.DS_Store
yarn.lock
types
test/ts-use/tsconfig.tsbuildinfo
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Library provides implementations for most basics and many others can be found in
## Interfaces

```js
import { CID } from 'multiformats/cid'
import * as json from 'multiformats/codecs/json'
import CID from 'multiformats/cid'
import json from 'multiformats/codecs/json'
import { sha256 } from 'multiformats/hashes/sha2'

const bytes = json.encode({ hello: 'world' })
Expand Down Expand Up @@ -196,3 +196,4 @@ Licensed under either of
### Contribution

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.

32 changes: 14 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
"version": "0.0.0-dev",
"description": "Interface for multihash, multicodec, multibase and CID",
"main": "./src/index.js",
"types": "./types/index.d.ts",
"type": "module",
"scripts": {
"build": "npm run build:js && npm run build:types",
"build:js": "npm_config_yes=true ipjs build --tests --main && npm run build:copy",
"build:copy": "cp -a tsconfig.json src vendor test dist/",
"build:types": "npm run build:copy && cd dist && tsc --build",
"build:js": "npm_config_yes=true ipjs build --tests",
"build:types": "tsc --emitDeclarationOnly --declarationDir dist/types",
"build:vendor": "npm run build:vendor:varint && npm run build:vendor:base-x",
"build:vendor:varint": "npx brrp -x varint > vendor/varint.js",
"build:vendor:base-x": "npx brrp -x @multiformats/base-x > vendor/base-x.js",
"publish": "npm_config_yes=true ipjs publish",
"lint": "standard",
"check": "tsc --build --noErrorTruncation",
"check": "tsc --noEmit --noErrorTruncation",
"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:cjs:browser": "polendina --page --worker --serviceworker --cleanup dist/cjs/browser-test/test-*.js",
Expand Down Expand Up @@ -86,16 +84,16 @@
}
},
"devDependencies": {
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"c8": "^7.6.0",
"@types/node": "14.14.3",
"@typescript-eslint/eslint-plugin": "^4.6.0",
"@typescript-eslint/parser": "^4.6.0",
"c8": "^7.3.5",
"hundreds": "0.0.9",
"ipjs": "^5.0.0",
"mocha": "^8.3.2",
"ipjs": "^3.4.4",
"mocha": "^8.2.0",
"polendina": "^1.1.0",
"standard": "^16.0.3",
"typescript": "^4.2.3"
"standard": "^15.0.0",
"typescript": "^4.0.3"
},
"standard": {
"ignore": [
Expand All @@ -104,8 +102,9 @@
]
},
"dependencies": {
"buffer": "^6.0.3",
"cids": "^1.1.6"
"buffer": "^5.6.1",
"cids": "^1.0.2",
"lodash.transform": "^4.6.0"
},
"directories": {
"test": "test"
Expand All @@ -122,9 +121,6 @@
"*": {
"*": [
"types/*"
],
"types/*": [
"types/*"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bases/base32.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { withAlphabet } from './base.js'
* @param {input} alphabet
*/
function decode (input, alphabet) {
input = input.replace(/=/g, '')
input = input.replace(new RegExp('=', 'g'), '')
const length = input.length

let bits = 0
Expand Down
4 changes: 2 additions & 2 deletions src/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as base32 from './bases/base32.js'
import * as base58 from './bases/base58.js'
import * as sha2 from './hashes/sha2.js'

import * as raw from './codecs/raw.js'
import * as json from './codecs/json.js'
import raw from './codecs/raw.js'
import json from './codecs/json.js'

import { CID, hasher, digest, varint, bytes } from './index.js'

Expand Down
3 changes: 1 addition & 2 deletions src/bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const equals = (aa, bb) => {
}

/**
* @param {ArrayBufferView|ArrayBuffer|Uint8Array} o
* @returns {Uint8Array}
* @param {ArrayBufferView|ArrayBuffer} o
*/
const coerce = o => {
if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array') return o
Expand Down
2 changes: 1 addition & 1 deletion src/cid.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { coerce } from './bytes.js'
* @typedef {import('./bases/interface').MultibaseDecoder<Prefix>} MultibaseDecoder
*/

export class CID {
export default class CID {
/**
* @param {0|1} version
* @param {number} code
Expand Down
51 changes: 44 additions & 7 deletions src/codecs/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
* @param {Code} options.code
* @param {(data:T) => Uint8Array} options.encode
* @param {(bytes:Uint8Array) => T} options.decode
* @returns {import('./interface').BlockCodec<Code, T>}
*/
export const codec = ({ name, code, decode, encode }) => {
const decoder = new Decoder(name, code, decode)
const encoder = new Encoder(name, code, encode)

return { name, code, decode, encode, decoder, encoder }
}
export const codec = ({ name, code, decode, encode }) =>
new Codec(name, code, encode, decode)

/**
* @template {number} Code
Expand Down Expand Up @@ -69,3 +64,45 @@ export class Decoder {
this.decode = decode
}
}

/**
* @template {number} Code
* @template T
* @typedef {import('./interface').BlockCodec<Code, T>} BlockCodec
*/

/**
* @class
* @template {string} Name
* @template {number} Code
* @template T
* @implements {BlockCodec<Code, T>}
*/
export class Codec {
/**
* @param {Name} name
* @param {Code} code
* @param {(data:T) => Uint8Array} encode
* @param {(bytes:Uint8Array) => T} decode
*/
constructor (name, code, encode, decode) {
this.name = name
this.code = code
this.encode = encode
this.decode = decode
}

get decoder () {
const { name, code, decode } = this
const decoder = new Decoder(name, code, decode)
Object.defineProperty(this, 'decoder', { value: decoder })
return decoder
}

get encoder () {
const { name, code, encode } = this
const encoder = new Encoder(name, code, encode)
Object.defineProperty(this, 'encoder', { value: encoder })
return encoder
}
}
5 changes: 1 addition & 4 deletions src/codecs/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export interface BlockDecoder<Code extends number, T> {
* separate those capabilties as sender requires encoder and receiver
* requires decoder.
*/
export interface BlockCodec<Code extends number, T> extends BlockEncoder<Code, T>, BlockDecoder<Code, T> {
encoder: BlockEncoder<Code, T>,
decoder: BlockDecoder<Code, T>
}
export interface BlockCodec<Code extends number, T> extends BlockEncoder<Code, T>, BlockDecoder<Code, T> { }


// This just a hack to retain type information abouth the data that
Expand Down
2 changes: 1 addition & 1 deletion src/codecs/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { codec } from './codec.js'

export const { name, code, decode, encode, decoder, encoder } = codec({
export default codec({
name: 'json',
code: 0x0200,
encode: json => new TextEncoder().encode(JSON.stringify(json)),
Expand Down
12 changes: 9 additions & 3 deletions src/codecs/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import { coerce } from '../bytes.js'
import { codec } from './codec.js'

export const { name, code, decode, encode, decoder, encoder } = codec({
/**
* @param {Uint8Array} bytes
* @returns {Uint8Array}
*/
const raw = (bytes) => coerce(bytes)

export default codec({
name: 'raw',
code: 85,
decode: coerce,
encode: coerce
decode: raw,
encode: raw
})
2 changes: 1 addition & 1 deletion src/hashes/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { from } from './hasher.js'
import { coerce } from '../bytes.js'

export const identity = from({
export default from({
name: 'identity',
code: 0x0,
encode: (input) => coerce(input)
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CID } from './cid.js'
import CID from './cid.js'
import * as varint from './varint.js'
import * as bytes from './bytes.js'
import * as hasher from './hashes/hasher.js'
Expand Down
5 changes: 3 additions & 2 deletions src/legacy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import OldCID from 'cids'
import * as bytes from './bytes.js'
import { Buffer } from 'buffer'
import { CID } from './cid.js'
import CID from './cid.js'

/**
* @template {number} Code
Expand All @@ -11,7 +11,7 @@ import { CID } from './cid.js'
* @param {Object<string, MultihashHasher>} options.hashes
*/

export const legacy = (codec, { hashes }) => {
const legacy = (codec, { hashes }) => {
/**
* @param {*} obj
*/
Expand Down Expand Up @@ -139,6 +139,7 @@ export const legacy = (codec, { hashes }) => {
return { defaultHashAlg, codec: codec.code, util, resolver }
}

export default legacy
/**
* @typedef {import('./hashes/interface').MultihashHasher} MultihashHasher
*/
Expand Down
2 changes: 1 addition & 1 deletion test/test-block.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals describe, it */
import * as codec from 'multiformats/codecs/json'
import codec from 'multiformats/codecs/json'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
import * as main from 'multiformats/block'
import { CID, bytes } from 'multiformats'
Expand Down
8 changes: 4 additions & 4 deletions test/test-legacy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* globals before, describe, it */
import { Buffer } from 'buffer'
import assert from 'assert'
import { legacy } from 'multiformats/legacy'
import * as rawCodec from 'multiformats/codecs/raw'
import * as jsonCodec from 'multiformats/codecs/json'
import legacy from 'multiformats/legacy'
import rawCodec from 'multiformats/codecs/raw'
import jsonCodec from 'multiformats/codecs/json'
import { sha256, sha512 } from 'multiformats/hashes/sha2'
import { codec } from 'multiformats/codecs/codec'
import { CID } from 'multiformats/cid'
import CID from 'multiformats/cid'

const same = assert.deepStrictEqual
const test = it
Expand Down
4 changes: 2 additions & 2 deletions test/test-multicodec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* globals describe, it */
import * as bytes from '../src/bytes.js'
import assert from 'assert'
import * as raw from 'multiformats/codecs/raw'
import * as json from 'multiformats/codecs/json'
import raw from 'multiformats/codecs/raw'
import json from 'multiformats/codecs/json'
import { codec } from 'multiformats/codecs/codec'
const same = assert.deepStrictEqual
const test = it
Expand Down
2 changes: 1 addition & 1 deletion test/test-multihash.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import valid from './fixtures/valid-multihash.js'
import invalid from './fixtures/invalid-multihash.js'
import crypto from 'crypto'
import { sha256, sha512, __browser } from 'multiformats/hashes/sha2'
import { identity } from 'multiformats/hashes/identity'
import identity from 'multiformats/hashes/identity'
import { decode as decodeDigest, create as createDigest } from 'multiformats/hashes/digest'
const test = it
const encode = name => data => coerce(crypto.createHash(name).update(data).digest())
Expand Down
2 changes: 1 addition & 1 deletion test/ts-use/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Block from 'multiformats/block'
import { sha256 } from 'multiformats/hashes/sha2'
import * as json from 'multiformats/codecs/json'
import json from 'multiformats/codecs/json'

const main = async () => {
const block = await Block.encode({
Expand Down
4 changes: 1 addition & 3 deletions test/ts-use/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"compilerOptions": {
"strict": true,
"moduleResolution": "node",
"noImplicitAny": true,
"skipLibCheck": true,
"incremental": true
"skipLibCheck": true
}
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "types",
"outDir": "dist",
"skipLibCheck": true,
"stripInternal": true,
"resolveJsonModule": true,
Expand Down