-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
752 additions
and
69 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
target | ||
index.node | ||
**/node_modules | ||
**/.DS_Store | ||
npm-debug.log* | ||
cargo.log | ||
cross.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "revolt-nodejs-bindings" | ||
version = "0.7.15" | ||
description = "Node.js bindings for the Revolt software" | ||
authors = ["Paul Makles <[email protected]>"] | ||
license = "MIT" | ||
edition = "2021" | ||
exclude = ["index.node"] | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
neon = "1.0.0" | ||
neon-serde4 = "1.0.0" | ||
|
||
serde = { version = "1", features = ["derive"] } | ||
|
||
async-std = "1.12.0" | ||
|
||
revolt-result = { version = "0.7.15", path = "../../core/result" } | ||
revolt-database = { version = "0.7.15", path = "../../core/database" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# revolt.node | ||
|
||
**revolt.node:** Node.js bindings for the Revolt software | ||
|
||
This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon). | ||
|
||
## Building revolt.node | ||
|
||
Building revolt.node requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support). | ||
|
||
To run the build, run: | ||
|
||
```sh | ||
$ npm run build | ||
``` | ||
|
||
This command uses the [@neon-rs/cli](https://www.npmjs.com/package/@neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`. | ||
|
||
## Exploring revolt.node | ||
|
||
After building revolt.node, you can explore its exports at the Node console: | ||
|
||
```sh | ||
$ npm i | ||
$ npm run build | ||
$ node | ||
> require('.').hello() | ||
'hello node' | ||
``` | ||
|
||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
#### `npm install` | ||
|
||
Installs the project, including running `npm run build`. | ||
|
||
#### `npm run build` | ||
|
||
Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`. | ||
|
||
Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm run build` and similar commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html): | ||
|
||
``` | ||
npm run build -- --feature=beetle | ||
``` | ||
|
||
#### `npm run debug` | ||
|
||
Similar to `npm run build` but generates a debug build with `cargo`. | ||
|
||
#### `npm run cross` | ||
|
||
Similar to `npm run build` but uses [cross-rs](https://github.com/cross-rs/cross) to cross-compile for another platform. Use the [`CARGO_BUILD_TARGET`](https://doc.rust-lang.org/cargo/reference/config.html#buildtarget) environment variable to select the build target. | ||
|
||
#### `npm test` | ||
|
||
Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/). | ||
|
||
## Project Layout | ||
|
||
The directory structure of this project is: | ||
|
||
``` | ||
revolt.node/ | ||
├── Cargo.toml | ||
├── README.md | ||
├── src/ | ||
| └── lib.rs | ||
├── index.node | ||
├── package.json | ||
└── target/ | ||
``` | ||
|
||
| Entry | Purpose | | ||
|----------------|------------------------------------------------------------------------------------------------------------------------------------------| | ||
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. | | ||
| `README.md` | This file. | | ||
| `src/` | The directory tree containing the Rust source code for the project. | | ||
| `lib.rs` | Entry point for the Rust source code. | | ||
| `index.node` | The main module, a [Node addon](https://nodejs.org/api/addons.html) generated by the build and pointed to by `"main"` in `package.json`. | | ||
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. | | ||
| `target/` | Binary artifacts generated by the Rust build. | | ||
|
||
## Learn More | ||
|
||
Learn more about: | ||
|
||
- [Neon](https://neon-bindings.com). | ||
- [Rust](https://www.rust-lang.org). | ||
- [Node](https://nodejs.org). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Channel, User } from "revolt-api"; | ||
|
||
/** | ||
* Opaque type for Revolt database | ||
*/ | ||
export declare interface Database {} | ||
|
||
/** | ||
* Opaque type for Revolt database | ||
*/ | ||
export declare interface OpaqueUser {} | ||
|
||
/** | ||
* Error type from Revolt backend | ||
*/ | ||
export declare interface Err { | ||
type: string; | ||
location: string; | ||
} | ||
|
||
/** | ||
* Gets a new handle to the Revolt database | ||
* @returns {Database} Handle | ||
*/ | ||
export declare function database(): Database; | ||
|
||
/** | ||
* Fetch user from database | ||
* @param {string} userId User's ID | ||
* @this {Database} | ||
*/ | ||
export declare function database_fetch_user(userId: string): OpaqueUser; | ||
|
||
/** | ||
* Fetch user from database | ||
* @param {string} username Username | ||
* @param {string} discriminator Discriminator | ||
* @this {Database} | ||
*/ | ||
export declare function database_fetch_user_by_username( | ||
username: string, | ||
discriminator: string | ||
): OpaqueUser; | ||
|
||
/** | ||
* Gets model data as JSON | ||
* @this {OpaqueUser} | ||
*/ | ||
export declare function model_data(): User; | ||
|
||
/** | ||
* Gets error if the model failed to fetch | ||
* @this {OpaqueUser} | ||
*/ | ||
export declare function model_error(): Err; | ||
|
||
/** | ||
* Open a direct message channel between two users | ||
* @param {string} userA User A ID | ||
* @param {string} userB User B ID | ||
* @returns Existing or newly created channel | ||
*/ | ||
export declare function proc_channels_create_dm( | ||
userA: string, | ||
userB: string | ||
): Promise<Channel & { error: Err }>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "revolt-nodejs-bindings", | ||
"version": "0.7.15", | ||
"description": "Node.js bindings for the Revolt software", | ||
"main": "index.node", | ||
"scripts": { | ||
"test": "cargo test", | ||
"cargo-build": "cargo build --message-format=json > cargo.log", | ||
"cross-build": "cross build --message-format=json > cross.log", | ||
"postcargo-build": "neon dist < cargo.log", | ||
"postcross-build": "neon dist -m /target < cross.log", | ||
"debug": "npm run cargo-build --", | ||
"build": "npm run cargo-build -- --release", | ||
"cross": "npm run cross-build -- --release" | ||
}, | ||
"author": "Paul Makles", | ||
"license": "AGPL-3.0", | ||
"devDependencies": { | ||
"@neon-rs/cli": "0.1.73" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/revoltchat/backend" | ||
}, | ||
"keywords": [ | ||
"revolt", | ||
"chat" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/revoltchat/backend/issues" | ||
}, | ||
"homepage": "https://github.com/revoltchat/backend#readme", | ||
"dependencies": { | ||
"revolt-api": "^0.7.15" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.