swarm
swarm copied to clipboard
A more general purpose API?
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.
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.
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:
- client-server connection using pluggable modules to deal with connection and security aspects (auth0 comes to my mind)
- pluggable database/data storage implementation on server side; I think it would be a major win to interface to proven systems such as Redis, PostgreSQL, etc. etc.
- bonus: support for additional server-side tiers, geographical distribution, etc.
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"?