Coder Social home page Coder Social logo

drifting-in-space / driftdb Goto Github PK

View Code? Open in Web Editor NEW
951.0 951.0 23.0 10.9 MB

A real-time data backend for browser-based applications.

Home Page: https://driftdb.com

License: MIT License

Dockerfile 0.76% Shell 0.58% Rust 33.55% TypeScript 56.56% CSS 0.15% JavaScript 8.41%

driftdb's People

Contributors

dav-s avatar felixharvey avatar fspoettel avatar kacesensitive avatar paulgb avatar pretentious7 avatar rolyatmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

driftdb's Issues

error: driftdb-worker should only be compiled to WebAssembly. Use driftdb-server for other targets.

$ git clone ...
$ cd driftdb
$ cargo build --release
...
   Compiling worker-macros v0.0.6
   Compiling worker v0.0.11
   Compiling driftdb-server v0.1.1 (/memfs/git/driftdb/driftdb-server)
   Compiling driftdb-worker v0.1.1 (/memfs/git/driftdb/driftdb-worker)
error: driftdb-worker should only be compiled to WebAssembly. Use driftdb-server for other targets.
   --> driftdb-worker/src/lib.rs:102:1
    |
102 | / compile_error!(
103 | |     "driftdb-worker should only be compiled to WebAssembly. Use driftdb-server for other targets."
104 | | );
    | |_^

error: could not compile `driftdb-worker` due to previous error
warning: build failed, waiting for other jobs to finish...

OS: FreeBSD 13.1-RELEASE-p5
cargo 1.66.1

[DIS-611] Improve optimistic application of shared reducers

Currently, shared reducers will advance optimistically on the client side, but slide back as states start coming in from the server.

Instead, we should:

  • Keep a queue of local messages that have been applied optimistically.
  • As messages from the server come in, compare them with the message at the back of the queue.
    • If the back of the queue is an exact match, discard it from the queue
    • If the back of the queue is not an exact match, throw out the queue and roll back and apply it

DIS-611

[DIS-610] Document vanilla JS API

People want to use DriftDB in non-React environments (Svelte and SolidJS so far). We should:

  • Extract useful bits that are currently in React hooks (collaborative compaction, debounced state storage) into the JS API
  • Document it

From SyncLinear.com | DIS-610

How to protect API token ?

I had signed up a api token for testing DriftDB, it's really wonderful product.
But in the network dev-tool, we can see the api token, And anyone can use it.
Is there some way to protect the token?
Thanks.

POSTing to http://localhost:8080/new returns 405 Method Not Allowed

$ xh post http://localhost:8080/new
HTTP/1.1 405 Method Not Allowed
Allow: GET,HEAD
Content-Length: 0
Date: Sat, 04 Feb 2023 13:31:05 GMT
$ ./driftdb-server
2023-02-04T13:31:05.110411Z  INFO request{method=POST uri=/new version=HTTP/1.1}: tower_http::trace::on_response: finished processing request latency=0 ms status=405

According to the docs:

Create a room by sending a POST request to /new. It returns a JSON object with the following fields:

    room: random string uniqely representing the new room (string).
    socket_url: WebSocket URL to connect to the room for real-time reads and write (string).
    http_url: HTTP URL to send messages to the room from non-WebSocket clients (string).

Given a room ID returned by /new, you can receive the same JSON object by sending a GET request to /room/<ROOM_ID>.

[DIS-615] Match the functionality of `useState` and `useReducer` in React

  • useSharedState should allow a function to be passed instead of a literal value. The function is evaluated on the current (local) value of the state.
  • useSharedReducer should take an optional init function that takes the prior argument and returns the first state.

The functions will still differ from their React counterparts in that they will take a key as the first parameter.

DIS-615

[DIS-723] CORS issue using POST /room/:room_id/send

#52 does not properly work if driftdb-server and clients are in different domains. Steps to reproduce:

  1. start drift-db server in localhost: ws://localhost:3000
  2. Open driftdb.com website and open Chrome dev tools, execute:
fetch('http://localhost:3000/new', {method:"post"}).then((response) => response.json()).then((data) => console.log(data))
  1. Open https://ui.driftdb.com/?url=ws://localhost:3000/room/<UUID from previous step>/connect in a new tab --> connects to the room.
  2. Go back to driftdb.com tab and execute:
fetch('http://localhost:3000/room/<UUID from previous step>/send', {method:"post", mode: "cors", body: JSON.stringify({
    "action": {"type": "append"},
    "key": "slider",
    "type": "push",
    "value": 55
})}).catch((error) => console.dir(error))

Result

POST http://localhost:3000/room/28573b90-a80c-4369-a2fa-c809c440a9d5/send 415 (Unsupported Media Type)
(anonymous) @ VM65:1
  1. Now try:
fetch('http://localhost:3000/room/28573b90-a80c-4369-a2fa-c809c440a9d5/send', {method:"post", mode: "cors", headers: { 'Content-Type': "application/json"}, body: JSON.stringify({
    "action": {"type": "append"},
    "key": "slider",
    "type": "push",
    "value": 55
})}).catch((error) => console.dir(error))

Result

Access to fetch at 'http://localhost:3000/room/28573b90-a80c-4369-a2fa-c809c440a9d5/send' from origin 'https://driftdb.com' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

Not confident to submit a PR, but tried the following and seems to work:

diff --git a/Cargo.lock b/Cargo.lock
index 2af49be..546c066 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -281,6 +281,7 @@ dependencies = [
  "clap",
  "dashmap",
  "driftdb",
+ "http",
  "hyper",
  "serde",
  "serde_json",
@@ -462,9 +463,9 @@ dependencies = [
 
 [[package]]
 name = "http"
-version = "0.2.8"
+version = "0.2.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
+checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
 dependencies = [
  "bytes",
  "fnv",
diff --git a/driftdb-server/Cargo.toml b/driftdb-server/Cargo.toml
index 96b4bd2..e22dd10 100644
--- a/driftdb-server/Cargo.toml
+++ b/driftdb-server/Cargo.toml
@@ -23,3 +23,4 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
 driftdb = {path = "../driftdb", version="0.1.0"}
 dashmap = "5.4.0"
 uuid = { version = "1.3.0", features = ["v4"] }
+http = "0.2.9"
diff --git a/driftdb-server/src/server.rs b/driftdb-server/src/server.rs
index 7d37dd2..f9890aa 100644
--- a/driftdb-server/src/server.rs
+++ b/driftdb-server/src/server.rs
@@ -16,6 +16,7 @@ use tower_http::{
     cors::{AllowOrigin, CorsLayer},
     trace::{DefaultMakeSpan, DefaultOnRequest, DefaultOnResponse, TraceLayer},
 };
+use http::header::{CONTENT_TYPE};
 use tracing::Level;
 use uuid::Uuid;
 
@@ -213,7 +214,8 @@ impl RoomResult {
 
 pub fn api_routes() -> Result<Router> {
     let cors = CorsLayer::new()
-        .allow_methods([Method::GET])
+        .allow_methods([Method::GET, Method::POST])
+        .allow_headers([CONTENT_TYPE])
         .allow_origin(AllowOrigin::any());
 
     let room_map = RoomMap::new();

DIS-723

A supply-chain security vulnerability found

Hi,

I'm a Cybersecurity researcher developing Packj [1]. Our tool has detected a supply-chain vulnerability in this repository. In order for me to disclose it, kindly enable GitHub Private vulnerability reporting, which allows security research to responsibly disclose a security vulnerability.

Thanks!

Packj detects malicious/"risky" NPM/PyPI/Ruby dependencies: https://github.com/ossillate-inc/packj

Possible to Use without React?

All the docs use React, but how would one use driftdb without a view library like react, simply using vanilla JS?

Please include some documentation for users who don't want to use Meta flux and related tools

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.