gritzko / swarm

JavaScript replicated model (M of MVC) library
http://swarmdb.net/
MIT License
2.68k stars 97 forks source link

A more general purpose API? #97

Open brodycj opened 6 years ago

brodycj commented 6 years ago

Looking through https://github.com/gritzko/swarm/tree/master/packages/client I get an impression that it should be possible to achieve some more flexibility by designing it to work with pluggable storage and backend connection drivers.

If we get it right then it may be possible to use the same module on the server side to coordinate between client connections, local cache or data storage, and lower tiers.

I would be happy to work on this idea if there is sufficient interest.

olebedev commented 6 years ago

Hi @brodybits,

Contributions are always welcome! Running the same code at all the tiers is a very interesting option.

Client already has interfaces for storage

export interface Storage {
  set(key: string, value: string): Promise<void>;
  get(key: string): Promise<?string>;
  remove(key: string): Promise<void>;
  keys(): Promise<Array<string>>;
}

and connection

export interface Connection {
  onmessage: (ev: MessageEvent) => any;
  onopen: (ev: Event) => any;
  send(data: string): void;
  readyState: number;
}

Does it fit your needs? If not, please provide more details.

brodycj commented 6 years ago

Thanks @olebedev for the response, it seems to make sense. I will probably have to read through the code some more to better understand what is needed to get it to properly support multiple tiers, with flexible pluggable components, with some things such as:

I would be happy to raise one or more new issues to discuss, if necessary.

I just raised #98 to ask about available documentation. I was also wondering what made you guys decide to merge this as a "monorepo"?