Skip to content

Commit 4f14996

Browse files
authored
fix: add doc-check script and export types used by functions (#637)
Uses tsc to attempt to compile any `typescript` code blocks in markdown files to ensure our examples don't get out of date.
1 parent f5a03fc commit 4f14996

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+313
-210
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ node_modules
77
package-lock.json
88
yarn.lock
99
.vscode
10+
.tmp-compiled-docs
11+
tsconfig-doc-check.aegir.json

benchmarks/add-dir/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build": "aegir build --bundle false",
1010
"lint": "aegir lint",
1111
"dep-check": "aegir dep-check",
12+
"doc-check": "aegir doc-check",
1213
"start": "npm run build && node dist/src/index.js"
1314
},
1415
"dependencies": {

benchmarks/gc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build": "aegir build --bundle false",
88
"lint": "aegir lint",
99
"dep-check": "aegir dep-check",
10+
"doc-check": "aegir doc-check",
1011
"start": "npm run build && node dist/src/index.js"
1112
},
1213
"dependencies": {

benchmarks/pinning/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build": "aegir build --bundle false",
88
"lint": "aegir lint",
99
"dep-check": "aegir dep-check",
10+
"doc-check": "aegir doc-check",
1011
"start": "npm run build && node dist/src/index.js"
1112
},
1213
"dependencies": {

benchmarks/transfer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build": "aegir build --bundle false",
1010
"lint": "aegir lint",
1111
"dep-check": "aegir dep-check",
12+
"doc-check": "aegir doc-check",
1213
"start": "npm run build && node dist/src/index.js"
1314
},
1415
"dependencies": {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"build": "aegir run build",
3131
"lint": "aegir run lint",
3232
"dep-check": "aegir run dep-check",
33+
"doc-check": "aegir run doc-check",
3334
"release": "run-s build docs:no-publish npm:release docs",
3435
"npm:release": "aegir exec --bail false npm -- publish",
3536
"release:rc": "aegir release-rc",

packages/bitswap/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

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

31+
export type { BitswapNetworkNotifyProgressEvents }
32+
export type { BitswapNetworkWantProgressEvents }
33+
export type { BitswapNetworkProgressEvents }
34+
export type { WantType }
35+
3136
export interface WantListEntry {
3237
cid: CID
3338
priority: number

packages/block-brokers/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"clean": "aegir clean",
4444
"lint": "aegir lint",
4545
"dep-check": "aegir dep-check",
46+
"doc-check": "aegir doc-check",
4647
"build": "aegir build",
4748
"test": "aegir test",
4849
"test:chrome": "aegir test -t browser --cov",

packages/block-brokers/src/bitswap.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import type { Blockstore } from 'interface-blockstore'
66
import type { CID } from 'multiformats/cid'
77
import type { MultihashHasher } from 'multiformats/hashes/interface'
88

9-
interface BitswapComponents {
9+
export interface BitswapBlockBrokerComponents {
1010
libp2p: Libp2p
1111
blockstore: Blockstore
1212
routing: Routing
1313
logger: ComponentLogger
1414
getHasher: HasherLoader
1515
}
1616

17-
export interface BitswapInit extends BitswapOptions {
17+
export interface BitswapBlockBrokerInit extends BitswapOptions {
1818

1919
}
2020

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

25-
constructor (components: BitswapComponents, init: BitswapInit = {}) {
25+
constructor (components: BitswapBlockBrokerComponents, init: BitswapBlockBrokerInit = {}) {
2626
const { getHasher } = components
2727

2828
this.bitswap = createBitswap(components, {
@@ -77,6 +77,6 @@ class BitswapBlockBroker implements BlockBroker<BitswapWantBlockProgressEvents,
7777
* A helper factory for users who want to override Helia `blockBrokers` but
7878
* still want to use the default `BitswapBlockBroker`.
7979
*/
80-
export function bitswap (init: BitswapInit = {}): (components: BitswapComponents) => BlockBroker {
80+
export function bitswap (init: BitswapBlockBrokerInit = {}): (components: BitswapBlockBrokerComponents) => BlockBroker {
8181
return (components) => new BitswapBlockBroker(components, init)
8282
}

packages/block-brokers/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export { bitswap } from './bitswap.js'
2+
export type { BitswapBlockBrokerInit, BitswapBlockBrokerComponents } from './bitswap.js'
23
export { trustlessGateway } from './trustless-gateway/index.js'
4+
export type { TrustlessGatewayBlockBrokerInit, TrustlessGatewayBlockBrokerComponents, TrustlessGatewayGetBlockProgressEvents } from './trustless-gateway/index.js'

packages/block-brokers/src/trustless-gateway/broker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createTrustlessGatewaySession } from './session.js'
22
import { findHttpGatewayProviders } from './utils.js'
33
import { DEFAULT_ALLOW_INSECURE, DEFAULT_ALLOW_LOCAL } from './index.js'
4-
import type { TrustlessGatewayBlockBrokerInit, TrustlessGatewayComponents, TrustlessGatewayGetBlockProgressEvents } from './index.js'
4+
import type { TrustlessGatewayBlockBrokerInit, TrustlessGatewayBlockBrokerComponents, TrustlessGatewayGetBlockProgressEvents } from './index.js'
55
import type { Routing, BlockRetrievalOptions, BlockBroker, CreateSessionOptions } from '@helia/interface'
66
import type { ComponentLogger, Logger } from '@libp2p/interface'
77
import type { CID } from 'multiformats/cid'
@@ -35,7 +35,7 @@ export class TrustlessGatewayBlockBroker implements BlockBroker<TrustlessGateway
3535
private readonly log: Logger
3636
private readonly logger: ComponentLogger
3737

38-
constructor (components: TrustlessGatewayComponents, init: TrustlessGatewayBlockBrokerInit = {}) {
38+
constructor (components: TrustlessGatewayBlockBrokerComponents, init: TrustlessGatewayBlockBrokerInit = {}) {
3939
this.log = components.logger.forComponent('helia:trustless-gateway-block-broker')
4040
this.logger = components.logger
4141
this.routing = components.routing

packages/block-brokers/src/trustless-gateway/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export interface TrustlessGatewayBlockBrokerInit {
2727
allowLocal?: boolean
2828
}
2929

30-
export interface TrustlessGatewayComponents {
30+
export interface TrustlessGatewayBlockBrokerComponents {
3131
routing: Routing
3232
logger: ComponentLogger
3333
}
3434

35-
export function trustlessGateway (init: TrustlessGatewayBlockBrokerInit = {}): (components: TrustlessGatewayComponents) => BlockBroker<TrustlessGatewayGetBlockProgressEvents> {
35+
export function trustlessGateway (init: TrustlessGatewayBlockBrokerInit = {}): (components: TrustlessGatewayBlockBrokerComponents) => BlockBroker<TrustlessGatewayGetBlockProgressEvents> {
3636
return (components) => new TrustlessGatewayBlockBroker(components, init)
3737
}

packages/car/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ import { CarWriter } from '@ipld/car'
4646
import { Readable } from 'node:stream'
4747
import nodeFs from 'node:fs'
4848

49-
const helia = createHelia({
49+
const helia = await createHelia({
5050
// ... helia config
5151
})
5252
const fs = unixfs(helia)
5353

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

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

78-
const helia = createHelia({
78+
const helia = await createHelia({
7979
// ... helia config
8080
})
8181

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

86+
const c = car(helia)
8687
await c.import(reader)
8788
```
8889

packages/car/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
"clean": "aegir clean",
129129
"lint": "aegir lint",
130130
"dep-check": "aegir dep-check",
131+
"doc-check": "aegir doc-check",
131132
"build": "aegir build",
132133
"test": "aegir test",
133134
"test:chrome": "aegir test -t browser --cov",

packages/car/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
* import { Readable } from 'node:stream'
1818
* import nodeFs from 'node:fs'
1919
*
20-
* const helia = createHelia({
20+
* const helia = await createHelia({
2121
* // ... helia config
2222
* })
2323
* const fs = unixfs(helia)
2424
*
2525
* // add some UnixFS data
26-
* const cid = await fs.addBytes(fileData1)
26+
* const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
2727
*
2828
* // export it as a Car
2929
* const c = car(helia)
@@ -46,14 +46,15 @@
4646
* import { Readable } from 'node:stream'
4747
* import nodeFs from 'node:fs'
4848
*
49-
* const helia = createHelia({
49+
* const helia = await createHelia({
5050
* // ... helia config
5151
* })
5252
*
5353
* // import the car
5454
* const inStream = nodeFs.createReadStream('example.car')
5555
* const reader = await CarReader.fromIterable(inStream)
5656
*
57+
* const c = car(helia)
5758
* await c.import(reader)
5859
* ```
5960
*/
@@ -78,7 +79,7 @@ export interface CarComponents {
7879
getCodec: CodecLoader
7980
}
8081

81-
interface ExportCarOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
82+
export interface ExportCarOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
8283
/**
8384
* If a filter is passed it will be used to deduplicate blocks exported in the car file
8485
*/

packages/dag-cbor/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ import { createHelia } from 'helia'
4141
import { dagCbor } from '@helia/dag-cbor'
4242
import { CID } from 'multiformats/cid'
4343

44+
const helia = await createHelia()
45+
4446
const d = dagCbor(helia)
45-
const cid = await d.put({
47+
const cid = await d.add({
4648
hello: 'world'
4749
})
4850
const obj = await d.get(cid)

packages/dag-cbor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
"clean": "aegir clean",
129129
"lint": "aegir lint",
130130
"dep-check": "aegir dep-check",
131+
"doc-check": "aegir doc-check",
131132
"build": "aegir build",
132133
"docs": "aegir docs",
133134
"test": "aegir test",

packages/dag-cbor/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
* import { dagCbor } from '@helia/dag-cbor'
1313
* import { CID } from 'multiformats/cid'
1414
*
15+
* const helia = await createHelia()
16+
*
1517
* const d = dagCbor(helia)
16-
* const cid = await d.put({
18+
* const cid = await d.add({
1719
* hello: 'world'
1820
* })
1921
* const obj = await d.get(cid)
@@ -75,9 +77,12 @@ export interface DAGCBOR {
7577
* @example
7678
*
7779
* ```typescript
80+
* import { createHelia } from 'helia'
7881
* import { dagCbor } from '@helia/dag-cbor'
7982
* import { CID } from 'multiformats/cid'
8083
*
84+
* const helia = await createHelia()
85+
*
8186
* const d = dagCbor(helia)
8287
* const cid = CID.parse('bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae')
8388
* const obj = await d.get(cid)

packages/dag-json/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ See the DAGJSON interface for all available operations.
3838

3939
```typescript
4040
import { createHelia } from 'helia'
41-
import { json } from '@helia/dag-json'
41+
import { dagJson } from '@helia/dag-json'
4242
import { CID } from 'multiformats/cid'
4343

44-
const j = json(helia)
45-
const cid = await j.put({
44+
const helia = await createHelia()
45+
const j = dagJson(helia)
46+
47+
const cid = await j.add({
4648
hello: 'world'
4749
})
4850
const obj = await j.get(cid)

packages/dag-json/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
"clean": "aegir clean",
129129
"lint": "aegir lint",
130130
"dep-check": "aegir dep-check",
131+
"doc-check": "aegir doc-check",
131132
"build": "aegir build",
132133
"test": "aegir test",
133134
"test:chrome": "aegir test -t browser --cov",

packages/dag-json/src/index.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
*
1010
* ```typescript
1111
* import { createHelia } from 'helia'
12-
* import { json } from '@helia/dag-json'
12+
* import { dagJson } from '@helia/dag-json'
1313
* import { CID } from 'multiformats/cid'
1414
*
15-
* const j = json(helia)
16-
* const cid = await j.put({
15+
* const helia = await createHelia()
16+
* const j = dagJson(helia)
17+
*
18+
* const cid = await j.add({
1719
* hello: 'world'
1820
* })
1921
* const obj = await j.get(cid)
@@ -57,9 +59,12 @@ export interface DAGJSON {
5759
* @example
5860
*
5961
* ```typescript
60-
* import { json } from '@helia/dag-json'
62+
* import { createHelia } from 'helia'
63+
* import { dagJson } from '@helia/dag-json'
64+
*
65+
* const helia = await createHelia()
66+
* const j = dagJson(helia)
6167
*
62-
* const j = json(helia)
6368
* const cid = await str.add({ hello: 'world' })
6469
*
6570
* console.info(cid)
@@ -75,10 +80,13 @@ export interface DAGJSON {
7580
* @example
7681
*
7782
* ```typescript
78-
* import { json } from '@helia/dag-json'
83+
* import { createHelia } from 'helia'
84+
* import { dagJson } from '@helia/dag-json'
7985
* import { CID } from 'multiformats/cid'
8086
*
81-
* const j = json(helia)
87+
* const helia = await createHelia()
88+
* const j = dagJson(helia)
89+
*
8290
* const cid = CID.parse('baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea')
8391
* const obj = await j.get(cid)
8492
*

packages/helia/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"clean": "aegir clean",
4444
"lint": "aegir lint",
4545
"dep-check": "aegir dep-check",
46+
"doc-check": "aegir doc-check",
4647
"build": "aegir build",
4748
"test": "aegir test",
4849
"test:chrome": "aegir test -t browser --cov",

packages/helia/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { HeliaP2P } from './helia-p2p.js'
2727
import { libp2pDefaults } from './utils/libp2p-defaults.js'
2828
import { createLibp2p } from './utils/libp2p.js'
2929
import type { DefaultLibp2pServices } from './utils/libp2p-defaults.js'
30+
import type { Libp2pDefaultsOptions } from './utils/libp2p.js'
3031
import type { Helia } from '@helia/interface'
3132
import type { HeliaInit as HeliaClassInit } from '@helia/utils'
3233
import type { Libp2p } from '@libp2p/interface'
@@ -38,7 +39,7 @@ import type { CID } from 'multiformats/cid'
3839
// if they don't want to
3940
export * from '@helia/interface'
4041

41-
export type { DefaultLibp2pServices }
42+
export type { DefaultLibp2pServices, Libp2pDefaultsOptions }
4243
export { libp2pDefaults }
4344

4445
/**

packages/http/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ fs.cat(CID.parse('bafyFoo'))
5454
```typescript
5555
import { createHeliaHTTP } from '@helia/http'
5656
import { trustlessGateway } from '@helia/block-brokers'
57-
import { delegatedHTTPRouting } from '@helia/routers'
57+
import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
5858
import { unixfs } from '@helia/unixfs'
5959
import { CID } from 'multiformats/cid'
6060

6161
const helia = await createHeliaHTTP({
6262
blockBrokers: [
63-
trustlessGateway({
64-
gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io'],
65-
}),
63+
trustlessGateway()
6664
],
6765
routers: [
68-
delegatedHTTPRouting('https://delegated-ipfs.dev')
66+
delegatedHTTPRouting('https://delegated-ipfs.dev'),
67+
httpGatewayRouting({
68+
gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io']
69+
})
6970
]
7071
})
7172

0 commit comments

Comments
 (0)