Skip to content

Commit

Permalink
fix: add doc-check script and export types used by functions (#637)
Browse files Browse the repository at this point in the history
Uses tsc to attempt to compile any `typescript` code blocks in
markdown files to ensure our examples don't get out of date.
  • Loading branch information
achingbrain authored Sep 23, 2024
1 parent f5a03fc commit 4f14996
Show file tree
Hide file tree
Showing 51 changed files with 313 additions and 210 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ node_modules
package-lock.json
yarn.lock
.vscode
.tmp-compiled-docs
tsconfig-doc-check.aegir.json
1 change: 1 addition & 0 deletions benchmarks/add-dir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "aegir build --bundle false",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"start": "npm run build && node dist/src/index.js"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions benchmarks/gc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "aegir build --bundle false",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"start": "npm run build && node dist/src/index.js"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions benchmarks/pinning/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "aegir build --bundle false",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"start": "npm run build && node dist/src/index.js"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions benchmarks/transfer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "aegir build --bundle false",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"start": "npm run build && node dist/src/index.js"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"build": "aegir run build",
"lint": "aegir run lint",
"dep-check": "aegir run dep-check",
"doc-check": "aegir run doc-check",
"release": "run-s build docs:no-publish npm:release docs",
"npm:release": "aegir exec --bail false npm -- publish",
"release:rc": "aegir release-rc",
Expand Down
7 changes: 6 additions & 1 deletion packages/bitswap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Bitswap as BitswapClass } from './bitswap.js'
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents } from './network.js'
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents, BitswapNetworkProgressEvents } from './network.js'
import type { WantType } from './pb/message.js'
import type { BlockBroker, CreateSessionOptions } from '@helia/interface'
import type { Routing } from '@helia/interface/routing'
Expand All @@ -28,6 +28,11 @@ export type BitswapWantBlockProgressEvents =
ProgressEvent<'bitswap:want-block:block', CID> |
BitswapNetworkWantProgressEvents

export type { BitswapNetworkNotifyProgressEvents }
export type { BitswapNetworkWantProgressEvents }
export type { BitswapNetworkProgressEvents }
export type { WantType }

export interface WantListEntry {
cid: CID
priority: number
Expand Down
1 change: 1 addition & 0 deletions packages/block-brokers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"build": "aegir build",
"test": "aegir test",
"test:chrome": "aegir test -t browser --cov",
Expand Down
8 changes: 4 additions & 4 deletions packages/block-brokers/src/bitswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import type { Blockstore } from 'interface-blockstore'
import type { CID } from 'multiformats/cid'
import type { MultihashHasher } from 'multiformats/hashes/interface'

interface BitswapComponents {
export interface BitswapBlockBrokerComponents {
libp2p: Libp2p
blockstore: Blockstore
routing: Routing
logger: ComponentLogger
getHasher: HasherLoader
}

export interface BitswapInit extends BitswapOptions {
export interface BitswapBlockBrokerInit extends BitswapOptions {

}

class BitswapBlockBroker implements BlockBroker<BitswapWantBlockProgressEvents, BitswapNotifyProgressEvents>, Startable {
private readonly bitswap: Bitswap
private started: boolean

constructor (components: BitswapComponents, init: BitswapInit = {}) {
constructor (components: BitswapBlockBrokerComponents, init: BitswapBlockBrokerInit = {}) {
const { getHasher } = components

this.bitswap = createBitswap(components, {
Expand Down Expand Up @@ -77,6 +77,6 @@ class BitswapBlockBroker implements BlockBroker<BitswapWantBlockProgressEvents,
* A helper factory for users who want to override Helia `blockBrokers` but
* still want to use the default `BitswapBlockBroker`.
*/
export function bitswap (init: BitswapInit = {}): (components: BitswapComponents) => BlockBroker {
export function bitswap (init: BitswapBlockBrokerInit = {}): (components: BitswapBlockBrokerComponents) => BlockBroker {
return (components) => new BitswapBlockBroker(components, init)
}
2 changes: 2 additions & 0 deletions packages/block-brokers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { bitswap } from './bitswap.js'
export type { BitswapBlockBrokerInit, BitswapBlockBrokerComponents } from './bitswap.js'
export { trustlessGateway } from './trustless-gateway/index.js'
export type { TrustlessGatewayBlockBrokerInit, TrustlessGatewayBlockBrokerComponents, TrustlessGatewayGetBlockProgressEvents } from './trustless-gateway/index.js'
4 changes: 2 additions & 2 deletions packages/block-brokers/src/trustless-gateway/broker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTrustlessGatewaySession } from './session.js'
import { findHttpGatewayProviders } from './utils.js'
import { DEFAULT_ALLOW_INSECURE, DEFAULT_ALLOW_LOCAL } from './index.js'
import type { TrustlessGatewayBlockBrokerInit, TrustlessGatewayComponents, TrustlessGatewayGetBlockProgressEvents } from './index.js'
import type { TrustlessGatewayBlockBrokerInit, TrustlessGatewayBlockBrokerComponents, TrustlessGatewayGetBlockProgressEvents } from './index.js'
import type { Routing, BlockRetrievalOptions, BlockBroker, CreateSessionOptions } from '@helia/interface'
import type { ComponentLogger, Logger } from '@libp2p/interface'
import type { CID } from 'multiformats/cid'
Expand Down Expand Up @@ -35,7 +35,7 @@ export class TrustlessGatewayBlockBroker implements BlockBroker<TrustlessGateway
private readonly log: Logger
private readonly logger: ComponentLogger

constructor (components: TrustlessGatewayComponents, init: TrustlessGatewayBlockBrokerInit = {}) {
constructor (components: TrustlessGatewayBlockBrokerComponents, init: TrustlessGatewayBlockBrokerInit = {}) {
this.log = components.logger.forComponent('helia:trustless-gateway-block-broker')
this.logger = components.logger
this.routing = components.routing
Expand Down
4 changes: 2 additions & 2 deletions packages/block-brokers/src/trustless-gateway/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export interface TrustlessGatewayBlockBrokerInit {
allowLocal?: boolean
}

export interface TrustlessGatewayComponents {
export interface TrustlessGatewayBlockBrokerComponents {
routing: Routing
logger: ComponentLogger
}

export function trustlessGateway (init: TrustlessGatewayBlockBrokerInit = {}): (components: TrustlessGatewayComponents) => BlockBroker<TrustlessGatewayGetBlockProgressEvents> {
export function trustlessGateway (init: TrustlessGatewayBlockBrokerInit = {}): (components: TrustlessGatewayBlockBrokerComponents) => BlockBroker<TrustlessGatewayGetBlockProgressEvents> {
return (components) => new TrustlessGatewayBlockBroker(components, init)
}
7 changes: 4 additions & 3 deletions packages/car/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ import { CarWriter } from '@ipld/car'
import { Readable } from 'node:stream'
import nodeFs from 'node:fs'

const helia = createHelia({
const helia = await createHelia({
// ... helia config
})
const fs = unixfs(helia)

// add some UnixFS data
const cid = await fs.addBytes(fileData1)
const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))

// export it as a Car
const c = car(helia)
Expand All @@ -75,14 +75,15 @@ import { CarReader } from '@ipld/car'
import { Readable } from 'node:stream'
import nodeFs from 'node:fs'

const helia = createHelia({
const helia = await createHelia({
// ... helia config
})

// import the car
const inStream = nodeFs.createReadStream('example.car')
const reader = await CarReader.fromIterable(inStream)

const c = car(helia)
await c.import(reader)
```

Expand Down
1 change: 1 addition & 0 deletions packages/car/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"build": "aegir build",
"test": "aegir test",
"test:chrome": "aegir test -t browser --cov",
Expand Down
9 changes: 5 additions & 4 deletions packages/car/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* import { Readable } from 'node:stream'
* import nodeFs from 'node:fs'
*
* const helia = createHelia({
* const helia = await createHelia({
* // ... helia config
* })
* const fs = unixfs(helia)
*
* // add some UnixFS data
* const cid = await fs.addBytes(fileData1)
* const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
*
* // export it as a Car
* const c = car(helia)
Expand All @@ -46,14 +46,15 @@
* import { Readable } from 'node:stream'
* import nodeFs from 'node:fs'
*
* const helia = createHelia({
* const helia = await createHelia({
* // ... helia config
* })
*
* // import the car
* const inStream = nodeFs.createReadStream('example.car')
* const reader = await CarReader.fromIterable(inStream)
*
* const c = car(helia)
* await c.import(reader)
* ```
*/
Expand All @@ -78,7 +79,7 @@ export interface CarComponents {
getCodec: CodecLoader
}

interface ExportCarOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
export interface ExportCarOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
/**
* If a filter is passed it will be used to deduplicate blocks exported in the car file
*/
Expand Down
4 changes: 3 additions & 1 deletion packages/dag-cbor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ import { createHelia } from 'helia'
import { dagCbor } from '@helia/dag-cbor'
import { CID } from 'multiformats/cid'

const helia = await createHelia()

const d = dagCbor(helia)
const cid = await d.put({
const cid = await d.add({
hello: 'world'
})
const obj = await d.get(cid)
Expand Down
1 change: 1 addition & 0 deletions packages/dag-cbor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"build": "aegir build",
"docs": "aegir docs",
"test": "aegir test",
Expand Down
7 changes: 6 additions & 1 deletion packages/dag-cbor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
* import { dagCbor } from '@helia/dag-cbor'
* import { CID } from 'multiformats/cid'
*
* const helia = await createHelia()
*
* const d = dagCbor(helia)
* const cid = await d.put({
* const cid = await d.add({
* hello: 'world'
* })
* const obj = await d.get(cid)
Expand Down Expand Up @@ -75,9 +77,12 @@ export interface DAGCBOR {
* @example
*
* ```typescript
* import { createHelia } from 'helia'
* import { dagCbor } from '@helia/dag-cbor'
* import { CID } from 'multiformats/cid'
*
* const helia = await createHelia()
*
* const d = dagCbor(helia)
* const cid = CID.parse('bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae')
* const obj = await d.get(cid)
Expand Down
8 changes: 5 additions & 3 deletions packages/dag-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ See the DAGJSON interface for all available operations.

```typescript
import { createHelia } from 'helia'
import { json } from '@helia/dag-json'
import { dagJson } from '@helia/dag-json'
import { CID } from 'multiformats/cid'

const j = json(helia)
const cid = await j.put({
const helia = await createHelia()
const j = dagJson(helia)

const cid = await j.add({
hello: 'world'
})
const obj = await j.get(cid)
Expand Down
1 change: 1 addition & 0 deletions packages/dag-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"build": "aegir build",
"test": "aegir test",
"test:chrome": "aegir test -t browser --cov",
Expand Down
22 changes: 15 additions & 7 deletions packages/dag-json/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
*
* ```typescript
* import { createHelia } from 'helia'
* import { json } from '@helia/dag-json'
* import { dagJson } from '@helia/dag-json'
* import { CID } from 'multiformats/cid'
*
* const j = json(helia)
* const cid = await j.put({
* const helia = await createHelia()
* const j = dagJson(helia)
*
* const cid = await j.add({
* hello: 'world'
* })
* const obj = await j.get(cid)
Expand Down Expand Up @@ -57,9 +59,12 @@ export interface DAGJSON {
* @example
*
* ```typescript
* import { json } from '@helia/dag-json'
* import { createHelia } from 'helia'
* import { dagJson } from '@helia/dag-json'
*
* const helia = await createHelia()
* const j = dagJson(helia)
*
* const j = json(helia)
* const cid = await str.add({ hello: 'world' })
*
* console.info(cid)
Expand All @@ -75,10 +80,13 @@ export interface DAGJSON {
* @example
*
* ```typescript
* import { json } from '@helia/dag-json'
* import { createHelia } from 'helia'
* import { dagJson } from '@helia/dag-json'
* import { CID } from 'multiformats/cid'
*
* const j = json(helia)
* const helia = await createHelia()
* const j = dagJson(helia)
*
* const cid = CID.parse('baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
* const obj = await j.get(cid)
*
Expand Down
1 change: 1 addition & 0 deletions packages/helia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"build": "aegir build",
"test": "aegir test",
"test:chrome": "aegir test -t browser --cov",
Expand Down
3 changes: 2 additions & 1 deletion packages/helia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { HeliaP2P } from './helia-p2p.js'
import { libp2pDefaults } from './utils/libp2p-defaults.js'
import { createLibp2p } from './utils/libp2p.js'
import type { DefaultLibp2pServices } from './utils/libp2p-defaults.js'
import type { Libp2pDefaultsOptions } from './utils/libp2p.js'
import type { Helia } from '@helia/interface'
import type { HeliaInit as HeliaClassInit } from '@helia/utils'
import type { Libp2p } from '@libp2p/interface'
Expand All @@ -38,7 +39,7 @@ import type { CID } from 'multiformats/cid'
// if they don't want to
export * from '@helia/interface'

export type { DefaultLibp2pServices }
export type { DefaultLibp2pServices, Libp2pDefaultsOptions }
export { libp2pDefaults }

/**
Expand Down
11 changes: 6 additions & 5 deletions packages/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ fs.cat(CID.parse('bafyFoo'))
```typescript
import { createHeliaHTTP } from '@helia/http'
import { trustlessGateway } from '@helia/block-brokers'
import { delegatedHTTPRouting } from '@helia/routers'
import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
import { unixfs } from '@helia/unixfs'
import { CID } from 'multiformats/cid'

const helia = await createHeliaHTTP({
blockBrokers: [
trustlessGateway({
gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io'],
}),
trustlessGateway()
],
routers: [
delegatedHTTPRouting('https://delegated-ipfs.dev')
delegatedHTTPRouting('https://delegated-ipfs.dev'),
httpGatewayRouting({
gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io']
})
]
})

Expand Down
Loading

0 comments on commit 4f14996

Please sign in to comment.