GithubHelp home page GithubHelp logo

Comments (18)

jaredwray avatar jaredwray commented on June 2, 2024 3

Hi All - Keyv Hooks are now up and running and we will be releasing v5.0.0-alpha.0 on NPM this weekend for testing. Just FYI.

from keyv.

jaredwray avatar jaredwray commented on June 2, 2024 1

@hugo082 - thanks and yes we are highly considering to move to a more stable model instead of using require. Will update as we get closer to alpha versions in the next couple weeks.

from keyv.

jaredwray avatar jaredwray commented on June 2, 2024 1

@gperdomor - thanks for your suggestion and I will plan to look at moving @keyv/redis to the standard driver as that does make sense. Working on getting v5 out and then will look at that.

from keyv.

hugo082 avatar hugo082 commented on June 2, 2024

Hi,

Thanks for the update!

With the current version, there is an import design issue that breaks the compatibility with bundlers (used by Next.js even for backend environments). please refer to #45 for more details.

To summarize, here is the part of the code that is responsible of the compatibility break. We are using require(adapters[adapter]) which is a require with expression and produces the following warning: the request of a dependency is an expression.

Is it possible to upgrade the v5 to be compatible with bundlers and remove this part of the code? It will produce a breaking change similar to:

import KeyvMemcache from '@keyv/memcache';
import Keyv from 'keyv';

// don't work anymore
const keyv = new Keyv('memcache://user:pass@localhost:11211');

// works
const keyv = new Keyv({ store: new KeyvMemcache('memcache://user:pass@localhost:11211') });

// proposals
const keyv = new Keyv(new KeyvMemcache('memcache://user:pass@localhost:11211'));
const keyv = new Keyv(KeyvMemcache, 'memcache://user:pass@localhost:11211');

from keyv.

lukechilds avatar lukechilds commented on June 2, 2024

Awesome progress, looking forward to seeing v5!

from keyv.

jaredwray avatar jaredwray commented on June 2, 2024

Awesome progress, looking forward to seeing v5!

@lukechilds - thanks so much one thing we will be discussing is if we want to go with the proposal as the require() functionality is going to cause issues with other libraries. Thoughts?

from keyv.

jaredwray avatar jaredwray commented on June 2, 2024

@hugo082 - updated with proposal

from keyv.

jaredwray avatar jaredwray commented on June 2, 2024

Added in information around hooks and statistics.

from keyv.

lukechilds avatar lukechilds commented on June 2, 2024

@lukechilds - thanks so much one thing we will be discussing is if we want to go with the proposal as the require() functionality is going to cause issues with other libraries. Thoughts?

Yeah if you wanna support bundling / frontend then I think probs best to remove dynamic require. I do think inferring deps via URI is pretty slick API design if it's possible to keep though. Potentially there could be some workaround that keeps the current behaviour without doing a dynamic require. Maybe some kind of shim that statically requires each dep on a best effort basis like:

storage-adaptors.js

try {
  module.exports.sqlite = require('sqlite')
} catch {}

try {
  module.exports.redis = require('redis')
} catch {}

then you could require the shim at runtime without error, check which storage adaptor you want to use, and return an error if it's undefined.

Potentially that could still cause issues with bundlers if they can't find redis at bundle time or whatever I'm not sure. Maybe defining them as peer deps could help? Could be worth investigating if you want to keep the URI API though.

from keyv.

lukechilds avatar lukechilds commented on June 2, 2024

But yeah if it's gonna be too much of a headache or isn't possible I think only accepting a storage adapter instance makes sense like:

const keyv = new Keyv({ store: storageAdaptor })

from keyv.

hugo082 avatar hugo082 commented on June 2, 2024

Potentially that could still cause issues with bundlers if they can't find redis at bundle time or whatever I'm not sure. Maybe defining them as peer deps could help? Could be worth investigating if you want to keep the URI API though.

The main issue I see with the try / catch approach is that the bundle cannot statically check so will try to bundle all dependencies (redis + sqlite).
There is maybe a solution to keep the same API by using TS Template literal types (which was introduced in typescript 4.1). I'm not sure it works but it may looks like

type SQLiteURI = `sqlite://${string}`;
type RedisURI = `redis://${string}`;
type URI = SQLiteURI | RedisURI;

const isRedisUri = (uri: URI): uri is RedisURI => uri.startsWith('redis://');
const isSQLiteUri = (uri: URI): uri is SQLiteURI => uri.startsWith('sqlite://');

const uri = 'redis://...'; // <= as to be a literal type, not only string

const clientFromUri = async (uri: URI) => {
  if (isRedisUri(uri)) {
    return await import('sqlite')
  } else if (isSQLiteUri(uri)) {
    return await import('redis')
  }

  assertType<never>(uri);
};

But it will still create a breaking change as the uri property as to be a literal type URI, not a string

from keyv.

jaredwray avatar jaredwray commented on June 2, 2024

Hi All - I wanted to update you on the progress leading up to v5 release. We have now split the repo into two branches:

  • main - this is now the v5 branch and we will be adding to it there. We do plan to put a link to the v4 branch.
  • v4 - this is now the v4 branch and the goal is to maintain this through 2024.

The current branch is now completely in typescript and also has updated types. Our next step is to work on publishing the v5 alpha version for people to start testing and then roll out the rest of the features hooks, stats, browser compatibility, compression fixes, offline / tiering mode (multi storage adapters), and namespace enhancements.

from keyv.

gperdomor avatar gperdomor commented on June 2, 2024

Hi all... I just discover this package and looks awesome... I have on doubt, any particular reason why you use ioredis instead official redis package?

Maybe the V5 can introduce a new store with the official package?

from keyv.

gperdomor avatar gperdomor commented on June 2, 2024

@jaredwray or maybe rename the current redis implementation to @keyv/ioredis in v5, in that way a new package @keyv/redis with official redis package can be created, I can help if you want :D

from keyv.

gperdomor avatar gperdomor commented on June 2, 2024

Hi again @jaredwray, it's me again... I want to know if there is any update regarding to the V5 release or if existe any beta version available?

from keyv.

gperdomor avatar gperdomor commented on June 2, 2024

seems like ioredis eventually will be deprecated according to this comment, so now it's more important a node-redid adapter πŸ™πŸ» redis/ioredis#1870 (comment)

from keyv.

jaredwray avatar jaredwray commented on June 2, 2024

seems like ioredis eventually will be deprecated according to this comment, so now it's more important a node-redid adapter πŸ™πŸ» redis/ioredis#1870 (comment)

Correct and we will be moving to the redis driver

from keyv.

jaredwray avatar jaredwray commented on June 2, 2024

Hi All! Wanted to update this thread as https://www.npmjs.com/package/keyv/v/5.0.0-rc.1 is now published as next and you can download it via npm install keyv@next to get the latest. Please note, you will also want to use the latest storage adapters if using typescript as it is compatible with v5. We will be publishing them over the next 24 hours and will tag the storage adapters with next. πŸŽ‰

This includes ESM and CJS support (CJS will get phased out most likely with Keyv v6), hooks, statistics, and moving to async/await with typescript and the following breaking change:

URI and Proposed Breaking Change πŸ”₯

After feedback from the community and looking into this more (thanks @hugo082) we have decided to longer support the uri on the constructor. This would be a major breaking change 😬 but we believe everything else will be worth it.

import KeyvMemcache from '@keyv/memcache';
import Keyv from 'keyv';

// don't work anymore
const keyv = new Keyv('memcache://user:pass@localhost:11211');

// works
const keyv = new Keyv({ store: new KeyvMemcache('memcache://user:pass@localhost:11211') });

// proposals moving forward. 
const keyv = new Keyv(new KeyvMemcache('memcache://user:pass@localhost:11211'));
const keyv = new Keyv(KeyvMemcache, 'memcache://user:pass@localhost:11211');
const keyv = new Keyv({ store: new KeyvMemcache('memcache://user:pass@localhost:11211') });

Finally, After more consideration we are going to get v5 live and past RC (we are planning that to be in June after testing) the plan moving forward is to do the final feature sets since they are non-breaking.

I will be closing this thread down and adding issues for the following features when it makes sense to track:

  • Storage Tiering - we are considering not adding this in because it seems to really be a feature that we want to support in caching systems such as cache-manager and cacheable long term but would love your feedback πŸ‘ or πŸ‘Ž
  • Namespacing - this is currently being planned out and should be non breaking change but will be later.
  • Simplified Compression Adapters - this will be added as an enhancement as time permits this year.

from keyv.

Related Issues (20)

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.