Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[admin] server-side instantdb/core #50

Open
stopachka opened this issue Aug 26, 2024 · 8 comments
Open

[admin] server-side instantdb/core #50

stopachka opened this issue Aug 26, 2024 · 8 comments

Comments

@stopachka
Copy link
Contributor

stopachka commented Aug 26, 2024

Could we have @instantdb/core work on the server?

Right now, only the @instantdb/core supports subscriptions to queries and presence. If we could run it on the server, users could subscribe to queries and see presence there.

We could then fold @instantdb/core into the admin SDK, and make it even more powerful.

@stopachka stopachka changed the title [admin] support presence subscriptions instant-client on the backend Aug 26, 2024
@stopachka stopachka changed the title instant-client on the backend [admin] subscriptions Aug 26, 2024
@stopachka stopachka changed the title [admin] subscriptions [admin] server-side instantdb/core Aug 26, 2024
@Exagone313
Copy link

I'm considering using Instant for side projects related to information and data aggregation. I would like to be able to create server-side workers and/or callable functions (FaaS) to fetch data, and be able to:

  • restrict access to the database with permissions, for increased security
  • use Instant's built-in real-time features for communicating with browser clients, instead of using other channels.

Note that this is purely hypothetical for now, I have not started using Instant, I just had a look at the docs and part of the source code.

@stopachka
Copy link
Contributor Author

One note:

It's possible to use the admin SDK to query 'on behalf' of users. This is useful if you want permissions to run for queries and transactions:

https://www.instantdb.com/docs/backend#impersonating-users

@Exagone313 's case may be different though, depending on the nature of the FaaS

@QuietRocket
Copy link

I'm glad this discussion is already open! Being able to run instantdb/core on the server is very interesting.
I'd like to run a simple Node, Bun or Deno server without any HTTP server. The server would subscribe to namespace changes and respond to those with additional writes. This would eliminate the need for HTTP endpoints.

I am interested in contributing for this, given that I've already started diving into both the admin and core code. Just not sure yet how to approach this optimally given there's multiple packages while keeping things DRY.

@timothyjoh
Copy link

I looked into this as well, thinking about building a chat room where 1-N "bots" are listening to a conversation and potentially responding after sending it to an LLM and back. Thinking "multiplayer, multi-NPC chat"

@gerhardcit
Copy link

gerhardcit commented Sep 13, 2024

@Exagone313 , you mentioned "data aggregation"
How would you count all the rows in a namespace, or by filter.
I cannot find the words aggregation, count or sum in the docs.
Considering it's a postgress database in the back, surely aggregation should be a thing.
If anything, that was the one thing where firebase fell flat.. (Firestore not as much). But still. How does one do that?
@stopachka . Aggregation?

@Exagone313
Copy link

Exagone313 commented Sep 13, 2024

I don't plan on using Instant for data aggregation by itself, but more as a mean of communication. Data aggregation will happen using other databases (or at least another connector if using the same PostgreSQL database - only applies when self-hosting). But I'm still not 100% sure about the implementation.

@Cixelyn
Copy link

Cixelyn commented Sep 30, 2024

chiming in as well, it seems @instantdb/core does not work in a server bun or nodejs environment, so it is not currently possible to use joinroom and subscribePresence for chatbot or realtime game-related usage cases like what @timothyjoh mentioned.

@ziruihao
Copy link

A temporary workaround is to mock the browser globals in your Node runtime. For example, If you inject global.window, global.document, and global.localStorage with the mock dom from a library like JSDom, the @instantdb/admin's joinRoom and subscribePresence should work.

We do hope for Node native support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants