Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"generate": "aegir run generate",
"build": "aegir run build",
"lint": "aegir run lint",
"docs": "NODE_OPTIONS=--max_old_space_size=4096 aegir docs",
"docs": "NODE_OPTIONS=--max_old_space_size=4096 aegir docs -- --exclude packages/interop",
"docs:no-publish": "npm run docs -- --publish false",
"dep-check": "aegir run dep-check",
"release": "npm run docs:no-publish && aegir run release && npm run docs"
"release": "npm run docs:no-publish && aegir run release && npm run docs -- --exclude packages/interop"
},
"devDependencies": {
"aegir": "^39.0.4"
"aegir": "^40.0.8"
},
"type": "module",
"workspaces": [
Expand Down
5 changes: 1 addition & 4 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@
},
"devDependencies": {
"@libp2p/peer-id-factory": "^2.0.3",
"aegir": "^39.0.4",
"aegir": "^40.0.8",
"body-parser": "^1.20.2"
},
"typedoc": {
"entryPoint": "./src/index.ts"
}
}
29 changes: 17 additions & 12 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
/**
* @packageDocumentation
*
* Create a Helia node.
* Create a client to use with a Routing V1 HTTP API server.
*
* @example
*
* ```typescript
* import { MemoryDatastore } from 'datastore-core'
* import { MemoryBlockstore } from 'blockstore-core'
* import { createHelia } from 'helia'
* import { unixfs } from '@helia/unixfs'
* import { createRoutingV1HttpApiClient } from '@helia/routing-v1-http-api-client'
* import { CID } from 'multiformats/cid'
*
* const node = await createHelia({
* blockstore: new MemoryBlockstore(),
* datastore: new MemoryDatastore()
* })
* const fs = unixfs(node)
* fs.cat(CID.parse('bafyFoo'))
* const client = createRoutingV1HttpApiClient(new URL('https://example.org'))
*
* for await (const prov of getProviders(CID.parse('QmFoo'))) {
* // ...
* }
* ```
*/

Expand All @@ -41,12 +37,21 @@ export interface RoutingV1HttpApiClientInit {
}

export interface RoutingV1HttpApiClient {
/**
* Returns an async generator of PeerInfos that can provide the content
* for the passed CID
*/
getProviders: (cid: CID, options?: AbortOptions) => AsyncGenerator<PeerInfo>

/**
* Shut down any currently running HTTP requests and clear up any resources
* that are in use
*/
stop: () => void
}

/**
* Create and return a Helia node
* Create and return a client to use with a Routing V1 HTTP API server
*/
export function createRoutingV1HttpApiClient (url: URL, init: RoutingV1HttpApiClientInit = {}): RoutingV1HttpApiClient {
return new DefaultRoutingV1HttpApiClient(url, init)
Expand Down
5 changes: 5 additions & 0 deletions packages/client/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"entryPoints": [
"./src/index.ts"
]
}
5 changes: 0 additions & 5 deletions packages/interop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
## Table of contents <!-- omit in toc -->

- [Install](#install)
- [API Docs](#api-docs)
- [License](#license)
- [Contribute](#contribute)

Expand All @@ -26,10 +25,6 @@
$ npm i @helia/routing-v1-http-api-interop
```

## API Docs

- <https://ipfs.github.io/helia-routing-v1-http-api/modules/_helia_routing_v1_http_api_client_interop.html>

## License

Licensed under either of
Expand Down
7 changes: 2 additions & 5 deletions packages/interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@
"@helia/interface": "^1.1.1",
"@libp2p/interface-libp2p": "^3.2.0",
"@libp2p/kad-dht": "^9.3.6",
"aegir": "^39.0.4",
"aegir": "^40.0.8",
"fastify": "^4.17.0",
"libp2p": "^0.45.4",
"multiformats": "^11.0.2"
},
"private": true,
"typedoc": {
"entryPoint": "./src/index.ts"
}
"private": true
}
5 changes: 1 addition & 4 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@
"@libp2p/peer-id-factory": "^2.0.3",
"@multiformats/multiaddr": "^12.1.3",
"@types/sinon": "^10.0.15",
"aegir": "^39.0.4",
"aegir": "^40.0.8",
"sinon": "^15.1.0",
"sinon-ts": "^1.0.0"
},
"typedoc": {
"entryPoint": "./src/index.ts"
}
}
16 changes: 7 additions & 9 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*
* const helia = await createHelia()
* const server = await createRoutingV1HttpApiServer(helia, {
* fastify: {
* // fastify options
* },
* listen: {
* // fastify listen options
* }
Expand Down Expand Up @@ -55,22 +52,23 @@
*/

import cors from '@fastify/cors'
import fastify, { type FastifyListenOptions, type FastifyHttpOptions, type FastifyHttpsOptions, type FastifyInstance } from 'fastify'
import fastify, {
type FastifyListenOptions,
type FastifyInstance
} from 'fastify'
import routes from './routes/index.js'
import type { Helia } from '@helia/interface'
import type * as http from 'node:http'
import type * as https from 'node:https'

export interface ServerInit {
fastify?: FastifyHttpOptions<http.Server> | FastifyHttpsOptions<https.Server>
fastify?: FastifyInstance
listen?: FastifyListenOptions
}

/**
* Create and return a Helia node
* Create and return a Routing V1 HTTP API server
*/
export async function createRoutingV1HttpApiServer (helia: Helia, init: ServerInit = {}): Promise<FastifyInstance> {
const server = fastify(init.fastify)
const server = init.fastify ?? fastify()
await server.register(cors, {
origin: '*',
methods: ['GET', 'OPTIONS'],
Expand Down
6 changes: 6 additions & 0 deletions packages/server/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"entryPoints": [
"./src/index.ts",
"./src/routes/index.ts"
]
}
4 changes: 4 additions & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://typedoc.org/schema.json",
"name": "Helia Routing V1 HTTP API"
}