Skip to content

Commit

Permalink
docs: use ts in examples, ensure package docs are up to date (#2323)
Browse files Browse the repository at this point in the history
Refs: #1777
  • Loading branch information
achingbrain authored Dec 18, 2023
1 parent dc56856 commit 07f3afe
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 50 deletions.
2 changes: 1 addition & 1 deletion doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ If enough peers report that this address is dialable, the node is free to change

For more information see https://docs.libp2p.io/concepts/nat/autonat/#what-is-autonat

```ts
```TypeScript
import { createLibp2p } from 'libp2p'
import { autoNATService } from '@libp2p/autonat'

Expand Down
16 changes: 8 additions & 8 deletions doc/LIMITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ We can also limit the number of connections in a 'pending' state. These connecti

All fields are optional. The default values are defined in [src/connection-manager/index.ts](https://github.com/libp2p/js-libp2p/blob/main/packages/libp2p/src/connection-manager/index.ts) - please see that file for the current values.

```ts
```TypeScript
import { createLibp2p } from 'libp2p'

const node = await createLibp2p({
Expand Down Expand Up @@ -57,7 +57,7 @@ const node = await createLibp2p({

When choosing connections to close the connection manager sorts the list of connections by the value derived from the tags given to each peer. The values of all tags are summed and connections with lower valued peers are eligible for closing first. If there are tags with equal values, the shortest-lived connection will be closed first.

```ts
```TypeScript
import { createLibp2p } from 'libp2p'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'

Expand Down Expand Up @@ -85,7 +85,7 @@ To prevent individual peers from opening multiple connections to a node, an `inb

All fields are optional. The default values are defined in [src/connection-manager/index.ts](https://github.com/libp2p/js-libp2p/blob/main/packages/libp2p/src/connection-manager/index.ts) - please see that file for the current values.

```ts
```TypeScript
import { createLibp2p } from 'libp2p'

const node = await createLibp2p({
Expand Down Expand Up @@ -113,7 +113,7 @@ These settings are done on a per-muxer basis, please see the README of the relev

All fields are optional. The default values are defined in [@libp2p/mplex/src/mplex.ts](https://github.com/libp2p/js-libp2p/blob/main/packages/stream-multiplexer-mplex/src/mplex.ts) - please see that file for the current values.

```ts
```TypeScript
import { createLibp2p } from 'libp2p'
import { mplex } from '@libp2p/mplex'

Expand Down Expand Up @@ -157,7 +157,7 @@ const node = await createLibp2p({

All fields are optional. The default values are defined in [@chainsafe/libp2p-yamux/src/config.ts](https://github.com/ChainSafe/js-libp2p-yamux/blob/master/src/config.ts) - please see that file for the current values.

```ts
```TypeScript
import { createLibp2p } from 'libp2p'
import { yamux } from '@chainsafe/libp2p-yamux'

Expand Down Expand Up @@ -194,7 +194,7 @@ Since incoming stream data is buffered until it is consumed, you should attempt

All fields are optional. The default values are defined in [src/registrar.ts](https://github.com/libp2p/js-libp2p/blob/main/packages/libp2p/src/registrar.ts) - please see that file for the current values.

```ts
```TypeScript
import { createLibp2p } from 'libp2p';

const node = await createLibp2p({});
Expand Down Expand Up @@ -224,7 +224,7 @@ The [@libp2p/tcp](https://github.com/libp2p/js-libp2p/tree/main/packages/transpo

All fields are optional. The full list of options is defined in [@libp2p/tcp/src/index.ts](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-tcp/src/index.ts) - please see that file for more details.

```ts
```TypeScript
import { createLibp2p } from 'libp2p'
import {tcp } from '@libp2p/tcp'

Expand Down Expand Up @@ -258,7 +258,7 @@ const node = await createLibp2p({

It is possible to configure some hosts to always accept connections from and some to always reject connections from.

```ts
```TypeScript
import { createLibp2p } from 'libp2p'

const node = await createLibp2p({
Expand Down
12 changes: 6 additions & 6 deletions doc/METRICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Although designed to primarily integrate with tools such as [Prometheus](https:/

First enable metrics tracking by supplying a [Metrics](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/metrics/index.ts#L150) implementation:

```ts
```TypeScript
import { createLibp2p } from 'libp2p'
import { prometheusMetrics } from '@libp2p/prometheus-metrics'

Expand Down Expand Up @@ -61,7 +61,7 @@ const node = await createLibp2p({

To define component metrics first get a reference to the metrics object:

```ts
```TypeScript
import type { Metrics } from '@libp2p/interface'

interface MyClassComponents {
Expand All @@ -83,7 +83,7 @@ class MyClass {

A tracked metric can be created by calling either `registerMetric` on the metrics object:

```ts
```TypeScript
import type { Metrics } from '@libp2p/interface'
import { prometheusMetrics } from '@libp2p/prometheus-metrics'

Expand Down Expand Up @@ -116,7 +116,7 @@ stopTimer()

A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped:

```ts
```TypeScript
import type { Metrics } from '@libp2p/interface'
import { prometheusMetrics } from '@libp2p/prometheus-metrics'

Expand All @@ -131,7 +131,7 @@ metrics.registerMetric('my_metric', {

If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead:

```ts
```TypeScript
import type { Metrics } from '@libp2p/interface'
import { prometheusMetrics } from '@libp2p/prometheus-metrics'

Expand Down Expand Up @@ -173,7 +173,7 @@ stopTimer()
Metrics implementations will allow extracting the values for presentation in an external system. For example here is how to use the metrics implementation from `@libp2p/prometheus-metrics` to enable scraping stats to display in [Prometheus](https://prometheus.io/) or a [Graphana](https://grafana.com/) dashboard. For more information, you can view our [docs](https://libp2p.github.io/js-libp2p-prometheus-metrics/)


```ts
```TypeScript
import { prometheusMetrics } from '@libp2p/prometheus-metrics'
import { createLibp2p } from 'libp2p'

Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,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.
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.
2 changes: 1 addition & 1 deletion packages/logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A logger for libp2p based on the venerable [debug](https://www.npmjs.com/package

## Example

```JavaScript
```TypeScript
import { logger } from '@libp2p/logger'

const log = logger('libp2p:my:component:name')
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @example
*
* ```JavaScript
* ```TypeScript
* import { logger } from '@libp2p/logger'
*
* const log = logger('libp2p:my:component:name')
Expand Down
65 changes: 65 additions & 0 deletions packages/peer-collections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,71 @@ We can't use PeerIds as collection keys because collection keys are compared usi

PeerIds cache stringified versions of themselves so this should be a cheap operation.

Tracked versions are also available which report their current size to the libp2p Metrics collector.

## Example - Peer lists

```TypeScript
import { peerList } from '@libp2p/peer-collections'

const list = peerList()
list.push(peerId)
```

## Example - Tracked peer lists

```TypeScript
import { trackedPeerList } from '@libp2p/peer-collections'
import { createLibp2p } from 'libp2p'

const libp2p = await createLibp2p()

const list = trackedPeerList({ name: 'my_metric_name', metrics: libp2p.metrics })
list.push(peerId)
```

## Example - Peer maps

```TypeScript
import { peerMap } from '@libp2p/peer-collections'

const map = peerMap<string>()
map.set(peerId, 'value')
```

## Example - Tracked peer maps

```TypeScript
import { trackedPeerMap } from '@libp2p/peer-collections'
import { createLibp2p } from 'libp2p'

const libp2p = await createLibp2p()

const list = trackedPeerMap({ name: 'my_metric_name', metrics: libp2p.metrics })
map.set(peerId, 'value')
```

## Example - Peer sets

```TypeScript
import { peerSet } from '@libp2p/peer-collections'

const set = peerSet()
set.add(peerId)
```

## Example - Tracked peer sets

```TypeScript
import { trackedPeerSet } from '@libp2p/peer-collections'
import { createLibp2p } from 'libp2p'

const libp2p = await createLibp2p()

const list = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics })
map.add(peerId)
```

# Install

```console
Expand Down
12 changes: 6 additions & 6 deletions packages/peer-collections/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @example Peer lists
*
* ```JavaScript
* ```TypeScript
* import { peerList } from '@libp2p/peer-collections'
*
* const list = peerList()
Expand All @@ -18,7 +18,7 @@
*
* @example Tracked peer lists
*
* * ```Typescript
* ```TypeScript
* import { trackedPeerList } from '@libp2p/peer-collections'
* import { createLibp2p } from 'libp2p'
*
Expand All @@ -30,7 +30,7 @@
*
* @example Peer maps
*
* ```JavaScript
* ```TypeScript
* import { peerMap } from '@libp2p/peer-collections'
*
* const map = peerMap<string>()
Expand All @@ -39,7 +39,7 @@
*
* @example Tracked peer maps
*
* * ```Typescript
* ```TypeScript
* import { trackedPeerMap } from '@libp2p/peer-collections'
* import { createLibp2p } from 'libp2p'
*
Expand All @@ -51,7 +51,7 @@
*
* @example Peer sets
*
* ```JavaScript
* ```TypeScript
* import { peerSet } from '@libp2p/peer-collections'
*
* const set = peerSet()
Expand All @@ -60,7 +60,7 @@
*
* @example Tracked peer sets
*
* * ```Typescript
* ```TypeScript
* import { trackedPeerSet } from '@libp2p/peer-collections'
* import { createLibp2p } from 'libp2p'
*
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-collections/src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { PeerId } from '@libp2p/interface'
*
* @example
*
* ```JavaScript
* ```TypeScript
* import { peerList } from '@libp2p/peer-collections'
*
* const list = peerList()
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-collections/src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { PeerId } from '@libp2p/interface'
*
* @example
*
* ```JavaScript
* ```TypeScript
* import { peerMap } from '@libp2p/peer-collections'
*
* const map = peerMap<string>()
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-collections/src/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { PeerId } from '@libp2p/interface'
*
* @example
*
* ```JavaScript
* ```TypeScript
* import { peerSet } from '@libp2p/peer-collections'
*
* const set = peerSet()
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-discovery-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ They will be tagged with a tag with the name `'bootstrap'` tag, the value `50` a

Clients that need constant connections to bootstrap nodes (e.g. browsers) can set the TTL to `Infinity`.

```JavaScript
```TypeScript
import { createLibp2p } from 'libp2p'
import { bootstrap } from '@libp2p/bootstrap'
import { tcp } from 'libp2p/tcp'
Expand Down
4 changes: 2 additions & 2 deletions packages/peer-discovery-bootstrap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Clients that need constant connections to bootstrap nodes (e.g. browsers) can set the TTL to `Infinity`.
*
* ```JavaScript
* ```TypeScript
* import { createLibp2p } from 'libp2p'
* import { bootstrap } from '@libp2p/bootstrap'
* import { tcp } from 'libp2p/tcp'
Expand Down Expand Up @@ -42,7 +42,7 @@
* const libp2p = await createLibp2p(options)
*
* libp2p.on('peer:discovery', function (peerId) {
* console.this.log('found peer: ', peerId.toB58String())
* console.log('found peer: ', peerId.toB58String())
* })
* ```
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-discovery-mdns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A peer discover mechanism that uses [mDNS](https://datatracker.ietf.org/doc/html

## Example

```ts
```TypeScript
import { mdns } from '@libp2p/mdns'

const options = {
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-discovery-mdns/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @example
*
* ```ts
* ```TypeScript
* import { mdns } from '@libp2p/mdns'
*
* const options = {
Expand Down
4 changes: 2 additions & 2 deletions packages/peer-id-factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
# About

Generate, import, and export PeerIDs, for use with [IPFS](https://github.com/ipfs/ipfs).
Generate, import, and export PeerIDs.

A Peer ID is the SHA-256 [multihash](https://github.com/multiformats/multihash) of a public key.

The public key is a base64 encoded string of a protobuf containing an RSA DER buffer. This uses a node buffer to pass the base64 encoded public key protobuf to the multihash for ID generation.

## Example

```JavaScript
```TypeScript
import { createEd25519PeerId } from '@libp2p/peer-id-factory'

const peerId = await createEd25519PeerId()
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-id-factory/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @example
*
* ```JavaScript
* ```TypeScript
* import { createEd25519PeerId } from '@libp2p/peer-id-factory'
*
* const peerId = await createEd25519PeerId()
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-id/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ An implementation of a peer id

## Example

```JavaScript
```TypeScript
import { peerIdFromString } from '@libp2p/peer-id'
const peer = peerIdFromString('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s')

Expand Down
Loading

0 comments on commit 07f3afe

Please sign in to comment.