refactor: remove crate bindings/node
This commit is contained in:
99
Cargo.lock
generated
99
Cargo.lock
generated
@@ -3986,16 +3986,6 @@ dependencies = [
|
|||||||
"pkg-config",
|
"pkg-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libloading"
|
|
||||||
version = "0.8.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"windows-targets 0.52.6",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
@@ -4489,43 +4479,6 @@ dependencies = [
|
|||||||
"tempfile",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "neon"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7d75440242411c87dc39847b0e33e961ec1f10326a9d8ecf9c1ea64a3b3c13dc"
|
|
||||||
dependencies = [
|
|
||||||
"getrandom",
|
|
||||||
"libloading",
|
|
||||||
"neon-macros",
|
|
||||||
"once_cell",
|
|
||||||
"semver",
|
|
||||||
"send_wrapper",
|
|
||||||
"smallvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "neon-macros"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c6813fde79b646e47e7ad75f480aa80ef76a5d9599e2717407961531169ee38b"
|
|
||||||
dependencies = [
|
|
||||||
"quote 1.0.38",
|
|
||||||
"syn 2.0.94",
|
|
||||||
"syn-mid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "neon-serde4"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8778b4afaa506e067da24566623873c38797987be593232a4f9ad82c84bb3eb3"
|
|
||||||
dependencies = [
|
|
||||||
"neon",
|
|
||||||
"num",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "new_debug_unreachable"
|
name = "new_debug_unreachable"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
@@ -4567,19 +4520,6 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
|
|
||||||
dependencies = [
|
|
||||||
"num-complex",
|
|
||||||
"num-integer",
|
|
||||||
"num-iter",
|
|
||||||
"num-rational",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-bigint"
|
name = "num-bigint"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -4607,15 +4547,6 @@ dependencies = [
|
|||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-complex"
|
|
||||||
version = "0.4.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-conv"
|
name = "num-conv"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -6233,19 +6164,6 @@ dependencies = [
|
|||||||
"validator 0.16.1",
|
"validator 0.16.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "revolt-nodejs-bindings"
|
|
||||||
version = "0.8.4"
|
|
||||||
dependencies = [
|
|
||||||
"async-std",
|
|
||||||
"neon",
|
|
||||||
"neon-serde4",
|
|
||||||
"revolt-config",
|
|
||||||
"revolt-database",
|
|
||||||
"revolt-result",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "revolt-parser"
|
name = "revolt-parser"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -6991,12 +6909,6 @@ version = "1.0.24"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba"
|
checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "send_wrapper"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sentry"
|
name = "sentry"
|
||||||
version = "0.31.8"
|
version = "0.31.8"
|
||||||
@@ -7587,17 +7499,6 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn-mid"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b5dc35bb08dd1ca3dfb09dce91fd2d13294d6711c88897d9a9d60acf39bce049"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote 1.0.38",
|
|
||||||
"syn 2.0.94",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sync_wrapper"
|
name = "sync_wrapper"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ members = [
|
|||||||
"crates/bonfire",
|
"crates/bonfire",
|
||||||
"crates/core/*",
|
"crates/core/*",
|
||||||
"crates/services/*",
|
"crates/services/*",
|
||||||
"crates/bindings/*",
|
|
||||||
"crates/daemons/*",
|
"crates/daemons/*",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ RUN sh /tmp/build-image-layer.sh tools
|
|||||||
|
|
||||||
# Build all dependencies
|
# Build all dependencies
|
||||||
COPY Cargo.toml Cargo.lock ./
|
COPY Cargo.toml Cargo.lock ./
|
||||||
COPY crates/bindings/node/Cargo.toml ./crates/bindings/node/
|
|
||||||
COPY crates/bonfire/Cargo.toml ./crates/bonfire/
|
COPY crates/bonfire/Cargo.toml ./crates/bonfire/
|
||||||
COPY crates/delta/Cargo.toml ./crates/delta/
|
COPY crates/delta/Cargo.toml ./crates/delta/
|
||||||
COPY crates/core/config/Cargo.toml ./crates/core/config/
|
COPY crates/core/config/Cargo.toml ./crates/core/config/
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ COPY scripts/build-image-layer.sh /tmp/
|
|||||||
|
|
||||||
# Build all dependencies
|
# Build all dependencies
|
||||||
COPY Cargo.toml Cargo.lock ./
|
COPY Cargo.toml Cargo.lock ./
|
||||||
COPY crates/bindings/node/Cargo.toml ./crates/bindings/node/
|
|
||||||
COPY crates/bonfire/Cargo.toml ./crates/bonfire/
|
COPY crates/bonfire/Cargo.toml ./crates/bonfire/
|
||||||
COPY crates/delta/Cargo.toml ./crates/delta/
|
COPY crates/delta/Cargo.toml ./crates/delta/
|
||||||
COPY crates/core/config/Cargo.toml ./crates/core/config/
|
COPY crates/core/config/Cargo.toml ./crates/core/config/
|
||||||
|
|||||||
31
README.md
31
README.md
@@ -12,22 +12,21 @@
|
|||||||
The services and libraries that power the Revolt service.<br/>
|
The services and libraries that power the Revolt service.<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
| Crate | Path | Description | |
|
| Crate | Path | Description | |
|
||||||
| ------------------ | -------------------------------------------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------ | -------------------------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `core/config` | [crates/core/config](crates/core/config) | Core: Configuration |     |
|
| `core/config` | [crates/core/config](crates/core/config) | Core: Configuration |     |
|
||||||
| `core/database` | [crates/core/database](crates/core/database) | Core: Database Implementation |     |
|
| `core/database` | [crates/core/database](crates/core/database) | Core: Database Implementation |     |
|
||||||
| `core/files` | [crates/core/files](crates/core/files) | Core: S3 and encryption subroutines |     |
|
| `core/files` | [crates/core/files](crates/core/files) | Core: S3 and encryption subroutines |     |
|
||||||
| `core/models` | [crates/core/models](crates/core/models) | Core: API Models |     |
|
| `core/models` | [crates/core/models](crates/core/models) | Core: API Models |     |
|
||||||
| `core/permissions` | [crates/core/permissions](crates/core/permissions) | Core: Permission Logic |     |
|
| `core/permissions` | [crates/core/permissions](crates/core/permissions) | Core: Permission Logic |     |
|
||||||
| `core/presence` | [crates/core/presence](crates/core/presence) | Core: User Presence |     |
|
| `core/presence` | [crates/core/presence](crates/core/presence) | Core: User Presence |     |
|
||||||
| `core/result` | [crates/core/result](crates/core/result) | Core: Result and Error types |     |
|
| `core/result` | [crates/core/result](crates/core/result) | Core: Result and Error types |     |
|
||||||
| `delta` | [crates/delta](crates/delta) | REST API server |  |
|
| `delta` | [crates/delta](crates/delta) | REST API server |  |
|
||||||
| `bonfire` | [crates/bonfire](crates/bonfire) | WebSocket events server |  |
|
| `bonfire` | [crates/bonfire](crates/bonfire) | WebSocket events server |  |
|
||||||
| `services/january` | [crates/services/january](crates/services/january) | Proxy server |  |
|
| `services/january` | [crates/services/january](crates/services/january) | Proxy server |  |
|
||||||
| `services/autumn` | [crates/services/autumn](crates/services/autumn) | File server |  |
|
| `services/autumn` | [crates/services/autumn](crates/services/autumn) | File server |  |
|
||||||
| `bindings/node` | [crates/bindings/node](crates/bindings/node) | Node.js bindings for the Revolt software |  |
|
| `daemons/crond` | [crates/daemons/crond](crates/daemons/crond) | Timed data clean up daemon server |  |
|
||||||
| `daemons/crond` | [crates/daemons/crond](crates/daemons/crond) | Timed data clean up daemon server |  |
|
| `daemons/pushd` | [crates/daemons/pushd](crates/daemons/pushd) | Push notification daemon server |  |
|
||||||
| `daemons/pushd` | [crates/daemons/pushd](crates/daemons/pushd) | Push notification daemon server |  |
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
7
crates/bindings/node/.gitignore
vendored
7
crates/bindings/node/.gitignore
vendored
@@ -1,7 +0,0 @@
|
|||||||
target
|
|
||||||
index.node
|
|
||||||
**/node_modules
|
|
||||||
**/.DS_Store
|
|
||||||
npm-debug.log*
|
|
||||||
cargo.log
|
|
||||||
cross.log
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "revolt-nodejs-bindings"
|
|
||||||
version = "0.8.4"
|
|
||||||
description = "Node.js bindings for the Revolt software"
|
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
|
||||||
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-config = { version = "0.8.4", path = "../../core/config" }
|
|
||||||
revolt-result = { version = "0.8.4", path = "../../core/result" }
|
|
||||||
revolt-database = { version = "0.8.4", path = "../../core/database" }
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
# 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).
|
|
||||||
84
crates/bindings/node/index.d.ts
vendored
84
crates/bindings/node/index.d.ts
vendored
@@ -1,84 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialises background tasks and logging, must be called before anything else!
|
|
||||||
* Can be called multiple times!
|
|
||||||
*/
|
|
||||||
export declare function init();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 }>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Suspend a user
|
|
||||||
* @param {string} user User
|
|
||||||
* @param {number} duration Duration (in days), set to 0 for indefinite
|
|
||||||
* @param {string} reason Pipe-separated list of reasons (e.g. reason1|reason2|reason3)
|
|
||||||
*/
|
|
||||||
export declare function proc_users_suspend(
|
|
||||||
user: OpaqueUser,
|
|
||||||
duration: number,
|
|
||||||
reason: string
|
|
||||||
): Promise<{ error: Err }>;
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "revolt-nodejs-bindings",
|
|
||||||
"version": "0.7.15-rev0.0.3",
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
117
crates/bindings/node/pnpm-lock.yaml
generated
117
crates/bindings/node/pnpm-lock.yaml
generated
@@ -1,117 +0,0 @@
|
|||||||
lockfileVersion: '6.0'
|
|
||||||
|
|
||||||
settings:
|
|
||||||
autoInstallPeers: true
|
|
||||||
excludeLinksFromLockfile: false
|
|
||||||
|
|
||||||
dependencies:
|
|
||||||
revolt-api:
|
|
||||||
specifier: ^0.7.15
|
|
||||||
version: 0.7.15
|
|
||||||
|
|
||||||
devDependencies:
|
|
||||||
'@neon-rs/cli':
|
|
||||||
specifier: 0.1.73
|
|
||||||
version: 0.1.73
|
|
||||||
|
|
||||||
packages:
|
|
||||||
|
|
||||||
/@cargo-messages/android-arm-eabi@0.1.72:
|
|
||||||
resolution: {integrity: sha512-gGZxIM1mj+Y5x+ULND6ZCNr7f70OJi9wDlycSK8hGONy9wrChN6JAIHryddC5cqcwlYAoQ6IDcDFElnhAYbybA==}
|
|
||||||
cpu: [arm]
|
|
||||||
os: [android]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cargo-messages/darwin-arm64@0.1.72:
|
|
||||||
resolution: {integrity: sha512-EAzN5MLaXPljZKZDO5qR+aBs44eSq2ZbEnS7AI/FziE3MzeXbrGOS3fLba5+7yWPFXJyZolXzePm8N1EBv8ovg==}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [darwin]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cargo-messages/darwin-x64@0.1.72:
|
|
||||||
resolution: {integrity: sha512-RLo6j8s3nYbjdd1LDct4wamfChyRit7zokUuxtIYCu9XOlltkN5vnj1vwnrPvoqCMZ/7CbbuHFwSTn9A71de/w==}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [darwin]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cargo-messages/linux-arm-gnueabihf@0.1.72:
|
|
||||||
resolution: {integrity: sha512-tHsRshuzfjrX6SDW3jg6al8vMNLTMgczGnVYl5RuBZf/yrAUuwe30KxA9ge6w6mW6Ox797DyBchzAc9OLgTgmQ==}
|
|
||||||
cpu: [arm]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cargo-messages/linux-x64-gnu@0.1.72:
|
|
||||||
resolution: {integrity: sha512-VGtL6CCnUbhsP4aYuBNT5kfrAL7o0qjrxw97a+ax13t+nJd26tVEEIKHMu5drvvS/Nm/hn7sLT8zMnnCv0pvHg==}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cargo-messages/win32-arm64-msvc@0.1.72:
|
|
||||||
resolution: {integrity: sha512-V93Cgz39K+yqa3MveNbhh29pYCp8izK5uEavjPoxlNxAbsMCWH+s0verGDdUcfGxjR1H2V7oZ4FszPqR2SqMRQ==}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [win32]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cargo-messages/win32-x64-msvc@0.1.72:
|
|
||||||
resolution: {integrity: sha512-knz3uSrO0OSbq3U5VWfCY8FB4NsM43BOWLZ7x4sfaMOC1XWv+IyvDdkLe6DhJx8KUw46KIAimYs9YROrp6l46Q==}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [win32]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@neon-rs/cli@0.1.73:
|
|
||||||
resolution: {integrity: sha512-1kv8S/feB6UQWQQwsnGfkSkEBOtlFDNExnioL81E2BwvUWgjQPaseHgpi2EpWVgsPUgur5eBm4QowmlpWkD4/w==}
|
|
||||||
hasBin: true
|
|
||||||
optionalDependencies:
|
|
||||||
'@cargo-messages/android-arm-eabi': 0.1.72
|
|
||||||
'@cargo-messages/darwin-arm64': 0.1.72
|
|
||||||
'@cargo-messages/darwin-x64': 0.1.72
|
|
||||||
'@cargo-messages/linux-arm-gnueabihf': 0.1.72
|
|
||||||
'@cargo-messages/linux-x64-gnu': 0.1.72
|
|
||||||
'@cargo-messages/win32-arm64-msvc': 0.1.72
|
|
||||||
'@cargo-messages/win32-x64-msvc': 0.1.72
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/axios@0.26.1:
|
|
||||||
resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==}
|
|
||||||
dependencies:
|
|
||||||
follow-redirects: 1.15.6
|
|
||||||
transitivePeerDependencies:
|
|
||||||
- debug
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/follow-redirects@1.15.6:
|
|
||||||
resolution: {integrity: sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==}
|
|
||||||
engines: {node: '>=4.0'}
|
|
||||||
peerDependencies:
|
|
||||||
debug: '*'
|
|
||||||
peerDependenciesMeta:
|
|
||||||
debug:
|
|
||||||
optional: true
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/lodash.defaultsdeep@4.6.1:
|
|
||||||
resolution: {integrity: sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/revolt-api@0.7.15:
|
|
||||||
resolution: {integrity: sha512-rWRnjBFvoXt/RHRxHg9KuP+x1Jk61KdsOpKOczVJg5tIqGDmqp/6QZHw5rJTtG+wCH3Ah3YKwY+MM5NHfg1W3Q==}
|
|
||||||
dependencies:
|
|
||||||
axios: 0.26.1
|
|
||||||
lodash.defaultsdeep: 4.6.1
|
|
||||||
transitivePeerDependencies:
|
|
||||||
- debug
|
|
||||||
dev: false
|
|
||||||
@@ -1,221 +0,0 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate serde;
|
|
||||||
|
|
||||||
use std::sync::OnceLock;
|
|
||||||
|
|
||||||
use neon::prelude::*;
|
|
||||||
use revolt_database::{Database, DatabaseInfo};
|
|
||||||
|
|
||||||
fn js_init(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
||||||
// static INIT: OnceLock<()> = OnceLock::new();
|
|
||||||
// if INIT.get().is_none() {
|
|
||||||
// INIT.get_or_init(|| {
|
|
||||||
// async_std::task::block_on(async {
|
|
||||||
// revolt_config::configure!(api);
|
|
||||||
|
|
||||||
// match DatabaseInfo::Auto.connect().await {
|
|
||||||
// Ok(db) => {
|
|
||||||
// let authifier_db = db.clone().to_authifier().await.database;
|
|
||||||
// revolt_database::tasks::start_workers(db, authifier_db);
|
|
||||||
// Ok(())
|
|
||||||
// }
|
|
||||||
// Err(err) => Err(err),
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .or_else(|err| cx.throw_error(err))
|
|
||||||
// .unwrap();
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
Ok(cx.undefined())
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DatabaseBinding(Database, Channel);
|
|
||||||
impl Finalize for DatabaseBinding {}
|
|
||||||
impl DatabaseBinding {
|
|
||||||
fn take(&self) -> (Database, Channel) {
|
|
||||||
(self.0.clone(), self.1.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn js_database(mut cx: FunctionContext) -> JsResult<JsBox<DatabaseBinding>> {
|
|
||||||
let db = async_std::task::block_on(DatabaseInfo::Auto.connect())
|
|
||||||
.or_else(|err| cx.throw_error(err))?;
|
|
||||||
|
|
||||||
let channel = cx.channel();
|
|
||||||
Ok(cx.boxed(DatabaseBinding(db, channel)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implementations for models
|
|
||||||
#[derive(Clone)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
enum Model {
|
|
||||||
User(revolt_database::User),
|
|
||||||
Error(revolt_result::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Model {
|
|
||||||
fn give(&self) -> Model {
|
|
||||||
self.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Finalize for Model {}
|
|
||||||
|
|
||||||
macro_rules! shim_boxed {
|
|
||||||
($cx: ident, $name: ident, $model: ident, $( $variable: ident $type: ident $id: expr )+, $cmd: ident, $( $arg: expr, )+) => {
|
|
||||||
fn $name(mut cx: FunctionContext) -> JsResult<JsPromise> {
|
|
||||||
$(
|
|
||||||
let $variable = cx.argument::<$type>($id)?.value(&mut cx);
|
|
||||||
)+
|
|
||||||
|
|
||||||
let (db, channel) = cx.this::<JsBox<DatabaseBinding>>()?.take();
|
|
||||||
let (deferred, promise) = cx.promise();
|
|
||||||
|
|
||||||
async_std::task::spawn(async move {
|
|
||||||
let result = db.$cmd($($arg,)+).await;
|
|
||||||
deferred.settle_with(&channel, move |mut cx| {
|
|
||||||
Ok(cx.boxed(match result {
|
|
||||||
Ok(value) => Model::$model(value),
|
|
||||||
Err(error) => Model::Error(error)
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(promise)
|
|
||||||
}
|
|
||||||
|
|
||||||
$cx.export_function(stringify!($name), $name)?;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn js_data(mut cx: FunctionContext) -> JsResult<JsValue> {
|
|
||||||
match cx.this::<JsBox<Model>>()?.give() {
|
|
||||||
Model::Error(_) => neon_serde4::to_value(&mut cx, &None::<()>),
|
|
||||||
Model::User(user) => neon_serde4::to_value(&mut cx, &user),
|
|
||||||
}
|
|
||||||
.or_else(|e| cx.throw_error(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn js_error(mut cx: FunctionContext) -> JsResult<JsValue> {
|
|
||||||
let value = match cx.this::<JsBox<Model>>()?.give() {
|
|
||||||
Model::Error(err) => Some(err),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
neon_serde4::to_value(&mut cx, &value).or_else(|e| cx.throw_error(e.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Basic data implementation
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct ResultBinding<T> {
|
|
||||||
#[serde(flatten)]
|
|
||||||
value: Option<T>,
|
|
||||||
error: Option<revolt_result::Error>,
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! shim {
|
|
||||||
($cx: ident, $name: ident, $( $variable: ident $type: ident $id: expr )*, $( $model: ident $modelType: ident $modelId: expr )*, | $db: ident | $closure: expr, $( $arg: expr, )+) => {
|
|
||||||
fn $name(mut cx: FunctionContext) -> JsResult<JsPromise> {
|
|
||||||
$(
|
|
||||||
let $variable = cx.argument::<$type>($id)?.value(&mut cx);
|
|
||||||
)*
|
|
||||||
|
|
||||||
$(
|
|
||||||
let mut $model = if let Model::$modelType(value) = cx.argument::<JsBox<Model>>($modelId)?.give() {
|
|
||||||
value
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
)*
|
|
||||||
|
|
||||||
let (db, channel) = cx.this::<JsBox<DatabaseBinding>>()?.take();
|
|
||||||
let (deferred, promise) = cx.promise();
|
|
||||||
|
|
||||||
async_std::task::spawn(async move {
|
|
||||||
#[allow(clippy::redundant_closure_call)]
|
|
||||||
let result = (|$db: $crate::Database| $closure)(db.clone()).await;
|
|
||||||
deferred.settle_with(&channel, move |mut cx| {
|
|
||||||
neon_serde4::to_value(
|
|
||||||
&mut cx,
|
|
||||||
&match result {
|
|
||||||
Ok(value) => ResultBinding {
|
|
||||||
value: Some(value),
|
|
||||||
error: None,
|
|
||||||
},
|
|
||||||
Err(error) => ResultBinding {
|
|
||||||
value: None,
|
|
||||||
error: Some(error),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.or_else(|e| cx.throw_error(e.to_string()))
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(promise)
|
|
||||||
}
|
|
||||||
|
|
||||||
$cx.export_function(stringify!($name), $name)?;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[neon::main]
|
|
||||||
fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
|
||||||
// initialise required background stuff
|
|
||||||
cx.export_function("init", js_init)?;
|
|
||||||
|
|
||||||
// database & model stuff
|
|
||||||
cx.export_function("database", js_database)?;
|
|
||||||
cx.export_function("model_data", js_data)?;
|
|
||||||
cx.export_function("model_error", js_error)?;
|
|
||||||
|
|
||||||
shim_boxed!(
|
|
||||||
cx,
|
|
||||||
database_fetch_user,
|
|
||||||
User,
|
|
||||||
user_id JsString 0,
|
|
||||||
fetch_user,
|
|
||||||
&user_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
shim_boxed!(
|
|
||||||
cx,
|
|
||||||
database_fetch_user_by_username,
|
|
||||||
User,
|
|
||||||
username JsString 0
|
|
||||||
discriminator JsString 1,
|
|
||||||
fetch_user_by_username,
|
|
||||||
&username, &discriminator,
|
|
||||||
);
|
|
||||||
|
|
||||||
// procedure calls
|
|
||||||
shim!(
|
|
||||||
cx,
|
|
||||||
proc_channels_create_dm,
|
|
||||||
user_a JsString 0
|
|
||||||
user_b JsString 1,
|
|
||||||
,
|
|
||||||
|db| async move {
|
|
||||||
let user_a = db.fetch_user(&user_a).await?;
|
|
||||||
let user_b = db.fetch_user(&user_b).await?;
|
|
||||||
revolt_database::Channel::create_dm(&db, &user_a, &user_b).await
|
|
||||||
},
|
|
||||||
&userA, &userB,
|
|
||||||
);
|
|
||||||
|
|
||||||
shim!(
|
|
||||||
cx,
|
|
||||||
proc_users_suspend,
|
|
||||||
duration JsNumber 1
|
|
||||||
reason JsString 2,
|
|
||||||
user User 0,
|
|
||||||
|db| async move {
|
|
||||||
let duration = duration as usize;
|
|
||||||
user.suspend(&db, if duration == 0 { None } else { Some(duration) }, Some(reason.split('|').map(|x| x.to_owned()).collect())).await
|
|
||||||
},
|
|
||||||
&user,
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
const Internal = require(".");
|
|
||||||
|
|
||||||
// playing around with class wrapper, not practical
|
|
||||||
class Model {
|
|
||||||
constructor(model) {
|
|
||||||
this.model = model;
|
|
||||||
}
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return Internal.model_data.bind(this.model)();
|
|
||||||
}
|
|
||||||
|
|
||||||
error() {
|
|
||||||
return Internal.model_error.bind(this.model)();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class User extends Model {
|
|
||||||
constructor(db, user) {
|
|
||||||
super(user);
|
|
||||||
this.db = db;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Database {
|
|
||||||
constructor() {
|
|
||||||
this.db = Internal.database();
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchUser(userId) {
|
|
||||||
return new User(
|
|
||||||
this,
|
|
||||||
await Internal.database_fetch_user.bind(this.db)(userId)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchUserByUsername(username, discriminator) {
|
|
||||||
return new User(
|
|
||||||
this,
|
|
||||||
await Internal.database_fetch_user_by_username.bind(this.db)(
|
|
||||||
username,
|
|
||||||
discriminator
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const db = new Database();
|
|
||||||
db.fetchUserByUsername("dos", "7624").then((user) => console.info(user.data()));
|
|
||||||
db.fetchUserByUsername("dos", "1111").then((user) => console.info(user.data()));
|
|
||||||
db.fetchUserByUsername("dos", "1111").then((user) =>
|
|
||||||
console.info(user.error())
|
|
||||||
);
|
|
||||||
6
crates/bindings/package-lock.json
generated
6
crates/bindings/package-lock.json
generated
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "bindings",
|
|
||||||
"lockfileVersion": 3,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,6 @@ tools() {
|
|||||||
|
|
||||||
deps() {
|
deps() {
|
||||||
mkdir -p \
|
mkdir -p \
|
||||||
crates/bindings/node/src \
|
|
||||||
crates/bonfire/src \
|
crates/bonfire/src \
|
||||||
crates/delta/src \
|
crates/delta/src \
|
||||||
crates/core/config/src \
|
crates/core/config/src \
|
||||||
@@ -45,7 +44,6 @@ deps() {
|
|||||||
tee crates/daemons/crond/src/main.rs |
|
tee crates/daemons/crond/src/main.rs |
|
||||||
tee crates/daemons/pushd/src/main.rs
|
tee crates/daemons/pushd/src/main.rs
|
||||||
echo '' |
|
echo '' |
|
||||||
tee crates/bindings/node/src/lib.rs |
|
|
||||||
tee crates/core/config/src/lib.rs |
|
tee crates/core/config/src/lib.rs |
|
||||||
tee crates/core/database/src/lib.rs |
|
tee crates/core/database/src/lib.rs |
|
||||||
tee crates/core/files/src/lib.rs |
|
tee crates/core/files/src/lib.rs |
|
||||||
|
|||||||
Reference in New Issue
Block a user