multiformats
Advanced tools
Comparing version 10.0.3 to 11.0.0
@@ -0,1 +1,23 @@ | ||
## [11.0.0](https://github.com/multiformats/js-multiformats/compare/v10.0.3...v11.0.0) (2023-01-02) | ||
### ⚠ BREAKING CHANGES | ||
* Make link.toJSON return a DAG-JSON link | ||
### Features | ||
* Make link.toJSON return a DAG-JSON link ([9e087d6](https://github.com/multiformats/js-multiformats/commit/9e087d64ee3c90d8b019dd48989936b17b1cb2f3)) | ||
### Bug Fixes | ||
* build browser bundle ([2ee6012](https://github.com/multiformats/js-multiformats/commit/2ee6012dbb702cff2425668c16fe101fdf79517d)), closes [#234](https://github.com/multiformats/js-multiformats/issues/234) | ||
* list links of a block that _is a_ CID ([#226](https://github.com/multiformats/js-multiformats/issues/226)) ([c17673d](https://github.com/multiformats/js-multiformats/commit/c17673d9e15bd5a4df074c9f73267a257e0dcfad)) | ||
### Documentation | ||
* fix typos in jsdoc comments ([a246054](https://github.com/multiformats/js-multiformats/commit/a246054653cf588e92d76f8161b0a6cd6035533b)) | ||
## [10.0.3](https://github.com/multiformats/js-multiformats/compare/v10.0.2...v10.0.3) (2022-12-16) | ||
@@ -2,0 +24,0 @@ |
{ | ||
"Codec": "https://multiformats.github.io/js-multiformats/classes/bases_base10._internal_.Codec.html", | ||
"ComposedDecoder": "https://multiformats.github.io/js-multiformats/classes/bases_base10._internal_.ComposedDecoder.html", | ||
"Decoder": "https://multiformats.github.io/js-multiformats/classes/bases_base10._internal_.Decoder.html", | ||
"Encoder": "https://multiformats.github.io/js-multiformats/classes/bases_base10._internal_.Encoder.html", | ||
"Decoders": "https://multiformats.github.io/js-multiformats/types/bases_base10._internal_.Decoders.html", | ||
"base10": "https://multiformats.github.io/js-multiformats/variables/bases_base10.base10.html", | ||
@@ -25,15 +30,15 @@ "base16": "https://multiformats.github.io/js-multiformats/variables/bases_base16.base16.html", | ||
"base8": "https://multiformats.github.io/js-multiformats/variables/bases_base8.base8.html", | ||
"identity": "https://multiformats.github.io/js-multiformats/variables/hashes_identity.identity.html", | ||
"identity": "https://multiformats.github.io/js-multiformats/variables/bases_identity.identity.html", | ||
"bases": "https://multiformats.github.io/js-multiformats/variables/basics.bases.html", | ||
"codecs": "https://multiformats.github.io/js-multiformats/variables/basics.codecs.html", | ||
"hashes": "https://multiformats.github.io/js-multiformats/variables/basics.hashes.html", | ||
"Block": "https://multiformats.github.io/js-multiformats/interfaces/index.Block.html", | ||
"Block": "https://multiformats.github.io/js-multiformats/classes/block.Block.html", | ||
"RequiredCreateOptions": "https://multiformats.github.io/js-multiformats/interfaces/block.RequiredCreateOptions.html", | ||
"create": "https://multiformats.github.io/js-multiformats/functions/link.create.html", | ||
"create": "https://multiformats.github.io/js-multiformats/functions/block.create.html", | ||
"createUnsafe": "https://multiformats.github.io/js-multiformats/functions/block.createUnsafe.html", | ||
"decode": "https://multiformats.github.io/js-multiformats/functions/link.decode.html", | ||
"encode": "https://multiformats.github.io/js-multiformats/functions/codecs_raw.encode.html", | ||
"decode": "https://multiformats.github.io/js-multiformats/functions/block.decode.html", | ||
"encode": "https://multiformats.github.io/js-multiformats/functions/block.encode.html", | ||
"empty": "https://multiformats.github.io/js-multiformats/variables/bytes.empty.html", | ||
"coerce": "https://multiformats.github.io/js-multiformats/functions/bytes.coerce.html", | ||
"equals": "https://multiformats.github.io/js-multiformats/functions/hashes_digest.equals.html", | ||
"equals": "https://multiformats.github.io/js-multiformats/functions/bytes.equals.html", | ||
"fromHex": "https://multiformats.github.io/js-multiformats/functions/bytes.fromHex.html", | ||
@@ -43,10 +48,11 @@ "fromString": "https://multiformats.github.io/js-multiformats/functions/bytes.fromString.html", | ||
"toHex": "https://multiformats.github.io/js-multiformats/functions/bytes.toHex.html", | ||
"toString": "https://multiformats.github.io/js-multiformats/functions/bytes.toString.html", | ||
"CID": "https://multiformats.github.io/js-multiformats/types/traversal.CID.html", | ||
"CID": "https://multiformats.github.io/js-multiformats/classes/cid.CID.html", | ||
"format": "https://multiformats.github.io/js-multiformats/functions/cid.format.html", | ||
"ByteView": "https://multiformats.github.io/js-multiformats/interfaces/index.ByteView.html", | ||
"code": "https://multiformats.github.io/js-multiformats/variables/codecs_raw.code.html", | ||
"name": "https://multiformats.github.io/js-multiformats/variables/codecs_raw.name.html", | ||
"fromJSON": "https://multiformats.github.io/js-multiformats/functions/cid.fromJSON.html", | ||
"toJSON": "https://multiformats.github.io/js-multiformats/functions/cid.toJSON.html", | ||
"ByteView": "https://multiformats.github.io/js-multiformats/types/codecs_json.ByteView.html", | ||
"code": "https://multiformats.github.io/js-multiformats/variables/codecs_json.code.html", | ||
"name": "https://multiformats.github.io/js-multiformats/variables/codecs_json.name.html", | ||
"Digest": "https://multiformats.github.io/js-multiformats/classes/hashes_digest.Digest.html", | ||
"MultihashDigest": "https://multiformats.github.io/js-multiformats/interfaces/index.MultihashDigest.html", | ||
"MultihashDigest": "https://multiformats.github.io/js-multiformats/types/hashes_digest.MultihashDigest.html", | ||
"Hasher": "https://multiformats.github.io/js-multiformats/classes/hashes_hasher.Hasher.html", | ||
@@ -69,2 +75,3 @@ "MultihashHasher": "https://multiformats.github.io/js-multiformats/interfaces/hashes_hasher.MultihashHasher.html", | ||
"Link": "https://multiformats.github.io/js-multiformats/interfaces/index.Link.html", | ||
"LinkJSON": "https://multiformats.github.io/js-multiformats/interfaces/index.LinkJSON.html", | ||
"MultibaseCodec": "https://multiformats.github.io/js-multiformats/interfaces/index.MultibaseCodec.html", | ||
@@ -71,0 +78,0 @@ "MultibaseDecoder": "https://multiformats.github.io/js-multiformats/interfaces/index.MultibaseDecoder.html", |
@@ -10,3 +10,3 @@ import { Link, Version } from '../link/interface.js'; | ||
* For example, a `ByteView<{ hello: "world" }>` is a `Uint8Array` containing a | ||
* binary representation of a `{hello: "world"}. | ||
* binary representation of a `{hello: "world"}`. | ||
*/ | ||
@@ -22,3 +22,3 @@ export interface ByteView<Data> extends Uint8Array, Phantom<Data> { | ||
* TypeScript does not natively support. Nominal types in turn allow us to capture | ||
* semantics not represented in the actual type structure, without requring us to define | ||
* semantics not represented in the actual type structure, without requiring us to define | ||
* new classes or pay additional runtime costs. | ||
@@ -25,0 +25,0 @@ * |
export * from "./link/interface.js"; | ||
export function format<T extends API.Link<unknown, number, number, API.Version>, Prefix extends string>(link: T, base?: API.MultibaseEncoder<Prefix> | undefined): API.ToString<T, Prefix>; | ||
export function toJSON<Link extends API.UnknownLink>(link: Link): API.LinkJSON<Link>; | ||
export function fromJSON<Link extends API.UnknownLink>(json: API.LinkJSON<Link>): CID<unknown, number, number, API.Version>; | ||
/** | ||
@@ -26,3 +28,3 @@ * @template {unknown} [Data=unknown] | ||
* class, but is compatible CID it will return new instance of this | ||
* `CID` class. Otherwise returs null. | ||
* `CID` class. Otherwise returns null. | ||
* | ||
@@ -190,5 +192,3 @@ * This allows two different incompatible versions of CID library to | ||
toJSON(): { | ||
code: Format; | ||
version: Version; | ||
hash: Uint8Array; | ||
'/': API.ToString<CID<Data, Format, Alg, Version>, string>; | ||
}; | ||
@@ -195,0 +195,0 @@ link(): CID<Data, Format, Alg, Version>; |
@@ -9,3 +9,3 @@ export function create<Code extends number>(code: Code, digest: Uint8Array): Digest<Code, number>; | ||
* Represents a multihash digest which carries information about the | ||
* hashing alogrithm and an actual hash digest. | ||
* hashing algorithm and an actual hash digest. | ||
* | ||
@@ -12,0 +12,0 @@ * @template {number} Code |
@@ -6,3 +6,2 @@ export * from "./link/interface.js"; | ||
export function parse<Prefix extends string, Data extends unknown, Code extends number, Alg extends number, Ver extends API.Version>(source: API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>, base?: API.MultibaseDecoder<Prefix> | undefined): API.Link<Data, Code, Alg, Ver>; | ||
export { format }; | ||
export function decode<Data extends unknown, Code extends number, Alg extends number, Ver extends API.Version>(bytes: API.ByteView<API.Link<Data, Code, Alg, Ver>>): API.Link<Data, Code, Alg, Ver>; | ||
@@ -13,2 +12,5 @@ import * as API from "./link/interface.js"; | ||
import { format } from "./cid.js"; | ||
import { toJSON } from "./cid.js"; | ||
import { fromJSON } from "./cid.js"; | ||
export { format, toJSON, fromJSON }; | ||
//# sourceMappingURL=link.d.ts.map |
@@ -25,10 +25,8 @@ import type { MultihashDigest } from '../hashes/interface.js'; | ||
toString: <Prefix extends string>(base?: MultibaseEncoder<Prefix>) => ToString<Link<Data, Format, Alg, Version>, Prefix>; | ||
toJSON: () => { | ||
version: V; | ||
code: Format; | ||
hash: Uint8Array; | ||
}; | ||
link: () => Link<Data, Format, Alg, V>; | ||
toV1: () => Link<Data, Format, Alg, 1>; | ||
} | ||
export interface LinkJSON<T extends UnknownLink = UnknownLink> { | ||
'/': ToString<T>; | ||
} | ||
export interface LegacyLink<T extends unknown = unknown> extends Link<T, DAG_PB, SHA_256, 0> { | ||
@@ -35,0 +33,0 @@ } |
{ | ||
"name": "multiformats", | ||
"version": "10.0.3", | ||
"version": "11.0.0", | ||
"description": "Interface for multihash, multicodec, multibase and CID", | ||
@@ -272,5 +272,2 @@ "author": "Mikeal Rogers <mikeal.rogers@gmail.com> (https://www.mikealrogers.com/)", | ||
"aegir": { | ||
"build": { | ||
"bundle": false | ||
}, | ||
"test": { | ||
@@ -277,0 +274,0 @@ "target": [ |
@@ -48,2 +48,6 @@ import { bytes as binary, CID } from './index.js' | ||
} | ||
const cid = CID.asCID(source) | ||
if (cid) { | ||
yield [base.join('/'), cid] | ||
} | ||
for (const [key, value] of Object.entries(source)) { | ||
@@ -50,0 +54,0 @@ const path = /** @type {[string|number, string]} */ ([...base, key]) |
@@ -13,3 +13,3 @@ /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */ | ||
* For example, a `ByteView<{ hello: "world" }>` is a `Uint8Array` containing a | ||
* binary representation of a `{hello: "world"}. | ||
* binary representation of a `{hello: "world"}`. | ||
*/ | ||
@@ -26,3 +26,3 @@ export interface ByteView<Data> extends Uint8Array, Phantom<Data> {} | ||
* TypeScript does not natively support. Nominal types in turn allow us to capture | ||
* semantics not represented in the actual type structure, without requring us to define | ||
* semantics not represented in the actual type structure, without requiring us to define | ||
* new classes or pay additional runtime costs. | ||
@@ -34,5 +34,5 @@ * | ||
export interface Phantom<T> { | ||
// This field can not be represented because field name is nonexistent | ||
// This field can not be represented because field name is non-existent | ||
// unique symbol. But given that field is optional any object will valid | ||
// type contstraint. | ||
// type constraint. | ||
[Marker]?: T | ||
@@ -39,0 +39,0 @@ } |
@@ -38,2 +38,18 @@ import * as varint from './varint.js' | ||
/** | ||
* @template {API.UnknownLink} Link | ||
* @param {Link} link | ||
* @returns {API.LinkJSON<Link>} | ||
*/ | ||
export const toJSON = (link) => ({ | ||
'/': format(link) | ||
}) | ||
/** | ||
* @template {API.UnknownLink} Link | ||
* @param {API.LinkJSON<Link>} json | ||
*/ | ||
export const fromJSON = (json) => | ||
CID.parse(json['/']) | ||
/** @type {WeakMap<API.UnknownLink, Map<string, string>>} */ | ||
@@ -204,7 +220,3 @@ const cache = new WeakMap() | ||
toJSON () { | ||
return { | ||
code: this.code, | ||
version: this.version, | ||
hash: this.multihash.bytes | ||
} | ||
return { '/': format(this) } | ||
} | ||
@@ -231,3 +243,3 @@ | ||
* class, but is compatible CID it will return new instance of this | ||
* `CID` class. Otherwise returs null. | ||
* `CID` class. Otherwise returns null. | ||
* | ||
@@ -234,0 +246,0 @@ * This allows two different incompatible versions of CID library to |
@@ -69,3 +69,3 @@ import { coerce, equals as equalBytes } from '../bytes.js' | ||
* Represents a multihash digest which carries information about the | ||
* hashing alogrithm and an actual hash digest. | ||
* hashing algorithm and an actual hash digest. | ||
* | ||
@@ -72,0 +72,0 @@ * @template {number} Code |
// Linter can see that API is used in types. | ||
// eslint-disable-next-line | ||
import * as API from "./link/interface.js" | ||
import { CID, format } from './cid.js' | ||
import { CID, format, toJSON, fromJSON } from './cid.js' | ||
// This way TS will also expose all the types from module | ||
@@ -76,3 +76,3 @@ export * from './link/interface.js' | ||
export { format } | ||
export { format, toJSON, fromJSON } | ||
@@ -79,0 +79,0 @@ /** |
@@ -38,3 +38,2 @@ /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */ | ||
toString: <Prefix extends string>(base?: MultibaseEncoder<Prefix>) => ToString<Link<Data, Format, Alg, Version>, Prefix> | ||
toJSON: () => { version: V, code: Format, hash: Uint8Array } | ||
link: () => Link<Data, Format, Alg, V> | ||
@@ -45,2 +44,6 @@ | ||
export interface LinkJSON<T extends UnknownLink = UnknownLink> { | ||
'/': ToString<T> | ||
} | ||
export interface LegacyLink<T extends unknown = unknown> extends Link<T, DAG_PB, SHA_256, 0> { | ||
@@ -47,0 +50,0 @@ } |
@@ -86,2 +86,13 @@ /* globals describe, it */ | ||
it('links of a block that is a CID', async () => { | ||
const block = await main.encode({ value: link, codec, hasher }) | ||
const links = [] | ||
for (const link of block.links()) { | ||
links.push(link) | ||
} | ||
assert.equal(links.length, 1) | ||
assert.equal(links[0][0], '') | ||
assert.equal(links[0][1].toString(), link.toString()) | ||
}) | ||
it('kitchen sink', () => { | ||
@@ -88,0 +99,0 @@ const sink = { one: { two: { arr: [true, false, null], three: 3, buff, link } } } |
@@ -485,9 +485,6 @@ /* globals describe, it */ | ||
const cid = CID.create(1, 112, hash) | ||
const json = cid.toJSON() | ||
assert.deepStrictEqual( | ||
{ ...json, hash: null }, | ||
{ code: 112, version: 1, hash: null } | ||
) | ||
assert.ok(equals(json.hash, hash.bytes)) | ||
assert.deepStrictEqual(cid.toJSON(), { | ||
'/': cid.toString() | ||
}) | ||
}) | ||
@@ -494,0 +491,0 @@ |
@@ -92,2 +92,38 @@ /* globals describe, it */ | ||
}) | ||
describe('toJSON', () => { | ||
assert.deepStrictEqual(Link.toJSON(Link.parse(h1)), { | ||
'/': h1 | ||
}) | ||
assert.deepStrictEqual(Link.toJSON(Link.parse(h4)), { | ||
'/': h4 | ||
}) | ||
}) | ||
describe('fromJSON', () => { | ||
assert.deepStrictEqual(Link.parse(h1), Link.fromJSON({ | ||
'/': h1 | ||
})) | ||
assert.deepStrictEqual(Link.parse(h1), Link.fromJSON({ | ||
'/': h1, | ||
// @ts-expect-error | ||
foo: 1 | ||
})) | ||
assert.deepStrictEqual(Link.parse(h4), Link.fromJSON({ | ||
'/': h4 | ||
})) | ||
}) | ||
describe('JSON.stringify', () => { | ||
assert.equal(JSON.stringify(Link.parse(h1)), JSON.stringify({ | ||
'/': h1 | ||
})) | ||
assert.equal(JSON.stringify(Link.parse(h4)), JSON.stringify({ | ||
'/': h4 | ||
})) | ||
}) | ||
}) | ||
@@ -94,0 +130,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
261847
160
5330