Skip to content

Commit

Permalink
start on the really big rest rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
splatterxl committed Aug 21, 2023
1 parent 9a05595 commit eb36d78
Show file tree
Hide file tree
Showing 36 changed files with 3,487 additions and 7,949 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
**/.env
.yarn/cache
.yarn/install-state.gz
**/.token
**/.token
pnpm-lock.yaml
2 changes: 1 addition & 1 deletion .hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ if git status | grep -q "\\.ts"; then
node scripts/prettify_changed.js
fi

yarn foreach precommit
pnpm foreach precommit
fi
546 changes: 0 additions & 546 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

This file was deleted.

9 changes: 0 additions & 9 deletions .yarn/plugins/@yarnpkg/plugin-typescript.cjs

This file was deleted.

550 changes: 0 additions & 550 deletions .yarn/plugins/@yarnpkg/plugin-version.cjs

This file was deleted.

49 changes: 0 additions & 49 deletions .yarn/releases/yarn-3.2.0.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions .yarn/versions/cde85f41.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .yarnrc.yml

This file was deleted.

23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ fuwa is a small, lightweight library for use in [Node.js] for interaction with
the popular text and VoIP instant messaging application [Discord] through its
[public bot API][discord-docs].

## installation.
## Installation

While fuwa is under heavy alpha development, some components of it are publicly
released. See [installation.md] for installation details.

## getting started.
## Getting started

fuwa is designed for use by developers familiar with the Discord API, and does
not provide heavy abstractions like other libraries. If this isn't for you, see
Expand All @@ -21,17 +21,18 @@ A simple ping/pong bot using [@fuwa/ws], [@fuwa/model], [@fuwa/rest] and
```js
import { GatewayManager } from '@fuwa/ws';
import { Message } from '@fuwa/model';
import { REST } from '@fuwa/rest';
import RESTManager from '@fuwa/rest';
import { APIMessage } from 'discord-api-types';

const gateway = new GatewayManager('my bot token');
const rest = new REST('Bot <my token>');
const rest = new RESTManager('Bot <my token>');

gateway.on('MESSAGE_CREATE', message => {
gateway.on('MESSAGE_CREATE', async (message: APIMessage) => {
// convert to a typed camelCase object
const msg = new Message(message);

if (msg.content.startsWith('!ping')) {
rest.createMessage(msg.channelID, {
await rest.createMessage(msg.channelID, {
content: 'pong!',
message_reference: {
message_id: msg.id,
Expand All @@ -41,12 +42,12 @@ gateway.on('MESSAGE_CREATE', message => {
});
```

## links.
## Links

- [documentation.](https://fuwa-org.github.io/fuwa)
- [repository.](https://github.com/fuwa-org/fuwa)
- [related projects.](https://discord.com/developers/docs/topics/community-resources)
- [discord server.](https://discord.gg/tDG9BMz5s7)
- [documentation](https://fuwa-org.github.io/fuwa)
- [repository](https://github.com/fuwa-org/fuwa)
- [related projects](https://discord.com/developers/docs/topics/community-resources)
- [discord server](https://discord.gg/tDG9BMz5s7)

[node.js]: https://nodejs.org
[discord]: https://discord.com
Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "@fuwa/fuwa",
"packageManager": "yarn@3.2.0",
"version": "1.0.0",
"main": "packages/fuwa/dist/index.js",
"scripts": {
"foreach": "bash scripts/foreach.sh yarn",
"foreach": "bash scripts/foreach.sh pnpm",
"lint": "eslint . --ext .ts",
"lint:fix": "yarn lint --fix",
"lint:fix": "pnpm lint --fix",
"build": "tsc",
"docs:build": "typedoc --options typedoc.json",
"docs:serve": "cd docs; python3 -m http.server",
"docs": "yarn docs:build && yarn docs:serve",
"docs": "pnpm docs:build && pnpm docs:serve",
"prettify": "prettier -w ."
},
"repository": {
Expand All @@ -23,10 +22,7 @@
"url": "https://github.com/fuwa-org/fuwa/issues"
},
"homepage": "https://github.com/fuwa-org/fuwa#readme",
"workspaces": [
"packages/*"
],
"devDependencies": {
"@changesets/cli": "^2.26.1"
"@changesets/cli": "^2.26.2"
}
}
7 changes: 3 additions & 4 deletions packages/fuwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "./dist/index.js",
"type": "commonjs",
"scripts": {
"precommit": "yarn build --noEmit && yarn lint",
"precommit": "pnpm build --noEmit && pnpm lint",
"lint": "eslint . --ext .ts",
"lint:fix": "yarn lint --fix",
"lint:fix": "pnpm lint --fix",
"build": "tsc",
"prettify": "prettier -w ."
},
Expand Down Expand Up @@ -43,6 +43,5 @@
"path": "./node_modules/cz-conventional-changelog"
}
},
"optionalPeerDependencies": {},
"packageManager": "yarn@3.2.0"
"optionalPeerDependencies": {}
}
2 changes: 1 addition & 1 deletion packages/model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Small library to facilitate JavaScript-ifying Discord objects",
"main": "dist/index.js",
"scripts": {
"precommit": "# yarn build --noEmit && yarn lint",
"precommit": "# pnpm build --noEmit && pnpm lint",
"build": "tsc"
},
"repository": {
Expand Down
41 changes: 34 additions & 7 deletions packages/rest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
# @fuwa/rest

## 0.4.0

### Major Changes

- changed certain endpoints from using function arguments for the JSON body to an object

```ts
import { REST } from '@fuwa/rest/dist';

const client = new REST()

await client.executeWebhook("webhookId", "token", "")
```

- renamed some endpoint methods to their equivalent in the Discord API docs
- moved from having `reason` and `with_*` options as their own arguments to having them inside an extended
version of `RequestOptions`


### Minor Changes

- add options to all `RESTManager` methods, providing access to options like whether to use auth, rate limits, etc.


## 0.3.0

### Minor Changes

- add REST entrypoint class

Similar to [ottercord](https://github.com/Commandtechno/ottercord) but all
Similar to [ottercord](https://github.com/Commandtechno/ottercord) but all
manual.

Its core function is to provide an easier method of interacting directly with
Its core function is to provide an easier method of interacting directly with
the API instead of using the main package and implementing the extra HTTP
boilerplate yourself.

- a new class, `REST`, which provides an almost [`@discordjs/rest`]-like feel
has been added
- easy methods and typings for documented routes have been added to the above
class
- eg: `REST.createMessage("channelId", { content: "a" })`
- a new class, `REST`, which provides an almost [`@discordjs/rest`]-like feel
has been added
- easy methods and typings for documented routes have been added to the above
class

```ts
client.createMessage("channelId", { content: "test" })
```
58 changes: 29 additions & 29 deletions packages/rest/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
# @fuwa/rest

A minimal, yet feature-complete, client for [Discord](https://discord.com)'s
public [REST API](https://discord.com/developers/docs). Uses undici.
public [REST API](https://discord.com/developers/docs). Uses undici internally.

Although the project is designed for Discord, it can be used for many types of
RESTful APIs.
# Installation

# installation.

```sh
yarn add @fuwa/rest
npm install --save @fuwa/rest
```shell
# using yarn
$ yarn add @fuwa/rest
# or pnpm
$ pnpm add @fuwa/rest
# or even npm
$ npm install --save @fuwa/rest
```

# usage.
# Usage

```js
import RESTManager, { RESTClient, DefaultDiscordOptions } from '@fuwa/rest';

const REST = new RESTManager(
new RESTClient({
...DefaultDiscordOptions,
auth: 'Bot <token>',
}),
);

REST.queue({
route: '/abc/def',
method: 'PATCH', // needs to be uppercase!
import { REST } from '@fuwa/rest';

const client = new REST("my_token");

await client.patch("/users/@me", {
body: {
foo: 'bar',
username: "fuwa_l0v3r"
},
})
// undici's ResponseData is returned
.then(d => d.body.json());
});

// want it simpler? here you go:
await client.editCurrentUser({
username: "fuwa_l0v3r_shorthand"
});
```

# documentation.
# Documentation

All endpoints under `REST` are represented by their name in the [Discord Developer Docs](https://discord.com/developers/docs).

Documentation is planned. Watch this space!
Documentation is planned and on the roadmap. Check back here later.

# links.
# Links

- [source.](https://github.com/fuwa-org/fuwa)
- [source code](https://github.com/fuwa-org/fuwa)
- [npm package](https://npmjs.com/@fuwa/rest)
4 changes: 2 additions & 2 deletions packages/rest/__test__/repl.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires, no-undef */
let __module__ = require('../typings');
let __module__ = require('..');
const repl = require('node:repl');

// allow autocompletion
Expand All @@ -16,7 +16,7 @@ const prompter = repl.start({
function reload() {
delete require.cache[require.resolve('..')];
// @ts-ignore
__module__ = require('../typings');
__module__ = require(require.resolve('..'));
r = new __module__.REST();
r.init.logger = {
debug: console.log,
Expand Down
8 changes: 4 additions & 4 deletions packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"main": "dist/index.js",
"types": "typings/index.d.ts",
"scripts": {
"precommit": "yarn build --noEmit && yarn lint",
"precommit": "pnpm build --noEmit && pnpm lint",
"build": "tsc",
"build:watch": "tsc -w",
"lint": "eslint . --ext .ts",
"lint:fix": "yarn lint --fix"
"lint:fix": "pnpm lint --fix"
},
"repository": {
"type": "git",
Expand All @@ -22,11 +22,11 @@
},
"homepage": "https://github.com/fuwa-org/fuwa#readme",
"devDependencies": {
"typescript": "^5.1.3"
"typescript": "^5.1.6"
},
"dependencies": {
"@sapphire/async-queue": "^1.5.0",
"discord-api-types": "^0.37.46",
"discord-api-types": "^0.37.48",
"form-data": "^4.0.0",
"undici": "^5.22.1"
}
Expand Down
58 changes: 0 additions & 58 deletions packages/rest/src/APIRequest.ts

This file was deleted.

Loading

0 comments on commit eb36d78

Please sign in to comment.