javascript-client icon indicating copy to clipboard operation
javascript-client copied to clipboard

Feature request: custom storage (factory)

Open jamesarosen opened this issue 2 years ago • 3 comments

I'd like to use Vercel KV as my storage. It's an implementation of Redis, but it doesn't expose a Redis URL. Instead, there's a JavaScript client library that supports the same methods.

Ideally, there would be some contract, expressed as a TypeScript interface, for a custom storage. I'd then be able to pass in my own factory instead of "memory" or "redis".

const factory = SplitFactory({
  storage: () => new MyCustomVercelKVStorage(),
})

Currently, that's impossible because getStorage is closure-scoped, as is getModules, which calls it.

Some additional benefits of this approach:

  • people could use other storage mechanisms like localStorage or Cloudflare KV
  • bundlers would be able to tree-shake this library better. As-is, they have to include both the memory and redis storage options because they're both required statically and resolved by a ternary statement

jamesarosen avatar Dec 22 '23 20:12 jamesarosen

Ah! This example suggests the solution is to use PluggableStorage from the browser SDK.

jamesarosen avatar Dec 22 '23 21:12 jamesarosen

This issue seems relevant again now that this library's README says,

The JavaScript SDK is an isomorphic library for both Node.js and Web browser environments.

jamesarosen avatar Jul 23 '24 12:07 jamesarosen

Yes @jamesarosen ,

As explained here, this package doesn't support custom storages yet :/.

Because of the benefits you mentioned, we plan to support it, but there is no ETA yet. Let's keep this issue open until we have a solution for it.

EmilianoSanchez avatar Jul 31 '24 16:07 EmilianoSanchez