Skip to content

Commit

Permalink
docs: set up typedoc for API docs (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng authored Jan 21, 2024
1 parent 8e238ca commit 6d3ff29
Show file tree
Hide file tree
Showing 29 changed files with 671 additions and 47 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# deploy docs to gh-pages branch
name: typedoc

on:
push:
branches:
- master

permissions:
contents: write

jobs:
deploy-docs-to-gh-pages:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2

- name: Retrieve the cached "node_modules" directory (if present)
uses: actions/cache@v2
id: node-cache
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}

- name: Install dependencies (if the cached directory was not found)
if: steps.node-cache.outputs.cache-hit != 'true'
run: npm ci

- name: Build the project
run: npm run build

- name: Unit tests
run: npm run test

- name: Create the docs directory
run: npm run docs

- name: Deploy 🚀
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: docs
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ lerna-debug.log
node_modules/
dist/
packages/*/dist/
coverage/
coverage/
docs/
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,65 @@
# nostr-relay

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FCodyTseng%2Fnostr-relay.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FCodyTseng%2Fnostr-relay?ref=badge_shield)

> Easily build your customized Nostr Relay.
## Usage

I think examples are the best way to explain how to use this library.

```typescript
import { NostrRelay, createOutgoingNoticeMessage } from '@nostr-relay/core';
import { EventRepositorySqlite } from '@nostr-relay/event-repository-sqlite';
import { Validator } from '@nostr-relay/validator';
import { WebSocketServer } from 'ws';

async function bootstrap() {
const wss = new WebSocketServer({ port: 4869 });

// You can implement your own event repository. It just needs to implement a few methods.
const eventRepository = new EventRepositorySqlite();
const relay = new NostrRelay(eventRepository);
const validator = new Validator();

wss.on('connection', ws => {
// Handle a new client connection. This method should be called when a new client connects to the Nostr Relay server.
relay.handleConnection(ws);

ws.on('message', async data => {
try {
// Validate the incoming message.
const message = await validator.validateIncomingMessage(data);
// Handle the incoming message.
await relay.handleMessage(ws, message);
} catch (error) {
if (error instanceof Error) {
ws.send(JSON.stringify(createOutgoingNoticeMessage(error.message)));
}
}
});

// Handle a client disconnection. This method should be called when a client disconnects from the Nostr Relay server.
ws.on('close', () => relay.handleDisconnect(ws));

ws.on('error', error => {
ws.send(JSON.stringify(createOutgoingNoticeMessage(error.message)));
});
});
}
bootstrap();
```

Full API documentation can be found [here](https://codytseng.github.io/nostr-relay/)

## Examples

- [nostr-relay-sqlite](https://github.com/CodyTseng/nostr-relay-sqlite)

## Donate

If you like this project, you can buy me a coffee :) ⚡️ [email protected] ⚡️

## License

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FCodyTseng%2Fnostr-relay.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FCodyTseng%2Fnostr-relay?ref=badge_large)
146 changes: 145 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"publish": "npm run clean && npm run build && lerna publish",
"lint": "eslint 'packages/**/**.ts' --ignore-pattern 'packages/**/*.spec.ts'",
"format": "prettier \"**/*.ts\" \"packages/**/*.json\" --ignore-path ./.prettierignore --write",
"test": "jest"
"test": "jest",
"docs": "typedoc"
},
"devDependencies": {
"@types/jest": "^29.5.11",
Expand All @@ -23,8 +24,15 @@
"lerna": "^8.0.0",
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"typedoc": "^0.25.7",
"typescript": "^5.3.2"
},
"optionalDependencies": {
"@nx/nx-darwin-arm64": "17.2.4",
"@nx/nx-darwin-x64": "17.2.4",
"@nx/nx-linux-x64-gnu": "17.2.4",
"@nx/nx-win32-x64-msvc": "17.2.4"
},
"jest": {
"clearMocks": true,
"collectCoverage": true,
Expand Down
8 changes: 8 additions & 0 deletions packages/common/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# @nostr-relay/common

> Easily build your customized Nostr Relay.
## API

Full API documentation can be found [here](https://codytseng.github.io/nostr-relay/modules/_nostr_relay_common.html)

## License

MIT
Loading

0 comments on commit 6d3ff29

Please sign in to comment.