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

feat: convert codebase to typescript #251

Merged
merged 16 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
12 changes: 12 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Semantic PR

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3
13 changes: 13 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Close and mark stale issue

on:
schedule:
- cron: '0 0 * * *'

permissions:
issues: write
pull-requests: write

jobs:
stale:
uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3
29 changes: 0 additions & 29 deletions .github/workflows/typecheck.yml

This file was deleted.

14 changes: 6 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
.coverage
package-lock.json
node_modules
.DS_Store
yarn.lock
types
test/ts-use/tsconfig.tsbuildinfo
types/tsconfig.tsbuildinfo
*.log
build
dist
.docs
.coverage
node_modules
package-lock.json
yarn.lock
.vscode
51 changes: 15 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
# multiformats <!-- omit in toc -->

[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiformats.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiformats)
[![CI](https://img.shields.io/github/actions/workflow/status/multiformats/js-multiformats/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/multiformats/js-multiformats/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)

> Interface for multihash, multicodec, multibase and CID

## Table of contents <!-- omit in toc -->

- [Install](#install)
- [Browser `<script>` tag](#browser-script-tag)
- [Interfaces](#interfaces)
- [Creating Blocks](#creating-blocks)
- [Multibase Encoders / Decoders / Codecs](#multibase-encoders--decoders--codecs)
- [Multicodec Encoders / Decoders / Codecs](#multicodec-encoders--decoders--codecs)
- [Multihash Hashers](#multihash-hashers)
- [Traversal](#traversal)
- [Legacy interface](#legacy-interface)
- [Implementations](#implementations)
- [Multibase codecs](#multibase-codecs)
- [Multihash hashers](#multihash-hashers-1)
- [IPLD codecs (multicodec)](#ipld-codecs-multicodec)
- [API Docs](#api-docs)
- [License](#license)
- [Contribution](#contribution)

## Install
# Install

```console
$ npm i multiformats
```

### Browser `<script>` tag
# Browser `<script>` tag

Loading this module through a script tag will make it's exports available as `Multiformats` in the global namespace.

```html
<script src="https://unpkg.com/multiformats/dist/index.min.js"></script>
```

## Interfaces
# Interfaces

This library defines common interfaces and low level building blocks for various interrelated multiformat technologies (multicodec, multihash, multibase, and CID). They can be used to implement custom base encoders / decoders / codecs, codec encoders /decoders and multihash hashers that comply to the interface that layers above assume.

Expand Down Expand Up @@ -80,7 +59,7 @@ block = await Block.decode({ bytes: block.bytes, codec, hasher })
block = await Block.create({ bytes: block.bytes, cid: block.cid, codec, hasher })
```

### Multibase Encoders / Decoders / Codecs
## Multibase Encoders / Decoders / Codecs

CIDs can be serialized to string representation using multibase encoders that implement [`MultibaseEncoder`](https://github.com/multiformats/js-multiformats/blob/master/src/bases/interface.ts) interface. This library provides quite a few implementations that can be imported:

Expand Down Expand Up @@ -123,7 +102,7 @@ v0.toV1().toString()
//> 'bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'
```

### Multicodec Encoders / Decoders / Codecs
## Multicodec Encoders / Decoders / Codecs

This library defines [`BlockEncoder`, `BlockDecoder` and `BlockCodec` interfaces](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts).
Codec implementations should conform to the `BlockCodec` interface which implements both `BlockEncoder` and `BlockDecoder`.
Expand All @@ -142,7 +121,7 @@ export const { name, code, encode, decode } = {
}
```

### Multihash Hashers
## Multihash Hashers

This library defines [`MultihashHasher` and `MultihashDigest` interfaces](https://github.com/multiformats/js-multiformats/blob/master/src/hashes/interface.ts) and convinient function for implementing them:

Expand All @@ -164,7 +143,7 @@ CID.create(1, json.code, hash)
//> CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)
```

### Traversal
## Traversal

This library contains higher-order functions for traversing graphs of data easily.

Expand Down Expand Up @@ -200,18 +179,18 @@ console.log(blocks)
//> [CID(bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea)]
```

## Legacy interface
# Legacy interface

[`blockcodec-to-ipld-format`](https://github.com/ipld/js-blockcodec-to-ipld-format) converts a multiformats [`BlockCodec`](https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts#L21) into an
[`interface-ipld-format`](https://github.com/ipld/interface-ipld-format) for use with the [`ipld`](https://github.com/ipld/ipld) package. This can help bridge IPLD codecs implemented using the structure and interfaces defined here to existing code that assumes, or requires `interface-ipld-format`. This bridge also includes the relevant TypeScript definitions.

## Implementations
# Implementations

By default, no base encodings (other than base32 & base58btc), hash functions,
or codec implementations are exposed by `multiformats`, you need to
import the ones you need yourself.

### Multibase codecs
## Multibase codecs

| bases | import | repo |
| ------------------------------------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------- |
Expand All @@ -222,7 +201,7 @@ import the ones you need yourself.

Other (less useful) bases implemented in [multiformats/js-multiformats](https://github.com/multiformats/js-multiformats/tree/master/bases) include: `base2`, `base8`, `base10`, `base36` and `base256emoji`.

### Multihash hashers
## Multihash hashers

| hashes | import | repo |
| ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
Expand All @@ -232,7 +211,7 @@ Other (less useful) bases implemented in [multiformats/js-multiformats](https://
| `murmur3-128`, `murmur3-32` | `@multiformats/murmur3` | [multiformats/js-murmur3](https://github.com/multiformats/js-murmur3) |
| `blake2b-*`, `blake2s-*` | `@multiformats/blake2` | [multiformats/js-blake2](https://github.com/multiformats/js-blake2) |

### IPLD codecs (multicodec)
## IPLD codecs (multicodec)

| codec | import | repo |
| ---------- | -------------------------- | ------------------------------------------------------------------------------------------------------ |
Expand All @@ -243,17 +222,17 @@ Other (less useful) bases implemented in [multiformats/js-multiformats](https://
| `dag-pb` | `@ipld/dag-pb` | [ipld/js-dag-pb](https://github.com/ipld/js-dag-pb) |
| `dag-jose` | `dag-jose` | [ceramicnetwork/js-dag-jose](https://github.com/ceramicnetwork/js-dag-jose) |

## API Docs
# API Docs

- <https://multiformats.github.io/js-multiformats>

## License
# License

Licensed under either of

- 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
# 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.
Loading