Code Monkey home page Code Monkey logo

seamless.ts's Introduction

seamless.ts

To install dependencies:

bun install

To run:

bun run dev

To build:

bun run build

To execute after build:

./dist/server

Goal

Provide a seamless way of creating APIs. The goal is to have an API that don't even notice.

Roadmap

  • Create a server that can be used to create APIs
  • Create a client that can be used to access the API
  • Support for nested objects
  • Support for arrays
  • Support for functions
  • Advanced array queries
  • Advanced authentication
  • Advanced authorization
  • DB integration

How it works

The server, which is written with Bun, provides a WebSocket and a REST API.

The client can subscribe to remote objects and get notified when they change.

For easier use, the client outputs a proxy object that can be used to access the remote objects as if they were local.

Nested objects aren't watched, instead, you have to replace the whole object, if you want to change a nested property.

Usage

// server
import { bundleClient } from "./bundle";
import { createServer, createModel } from "./lib";

const config = {
  message: "Hello World!",
  counter: 0,
  isAwesome: true,
  increment() {
    this.counter++;
  },
};

const configModel = createModel(config, (req, auth) => {
  if (auth.getBearerPassword() === "123") {
    return {
      write: true,
      read: true,
    };
  }
  return {
    write: false,
    read: true,
  };
});

const bundle = await bundleClient();
const clientCode = await bundle.outputs[0].text();

const server = createServer({
  models: {
    config: configModel,
  },
  bundle: clientCode,
});

server.listen(3000);
// client
const client = await import("http://localhost:3000/client.js");

const ws = new WebSocket("ws://localhost:3000/ws");

const manager = new client.RemoteObjectManager(ws, "123");

await new Promise((resolve) => setTimeout(resolve, 1000));

const config = await manager.subscribe("config");

config.message; // -> "Hello World!"

config.counter; // -> 0

config.counter = 1;

config.counter; // -> 1

seamless.ts's People

Contributors

jak2k avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

erdalga

seamless.ts's Issues

Array Queries

Currently, the whole array is loaded to the client, which is not very efficient.

It would be nice to be able to query the server for a subset of the array.

Support for Functions

Support for remote functions would be nice.

A function could be globally available or bound to a specific model.

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.