Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keyv

Package Overview
Dependencies
Maintainers
2
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keyv - npm Package Compare versions

Comparing version 5.0.0-rc.1 to 5.0.0

LICENSE

2

dist/cjs/hooks-manager.d.ts

@@ -1,2 +0,2 @@

import EventManager from './event-manager';
import EventManager from './event-manager.js';
type HookHandler = (...arguments_: any[]) => void;

@@ -3,0 +3,0 @@ declare class HooksManager extends EventManager {

@@ -6,4 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const event_manager_1 = __importDefault(require("./event-manager"));
class HooksManager extends event_manager_1.default {
const event_manager_js_1 = __importDefault(require("./event-manager.js"));
class HooksManager extends event_manager_js_1.default {
_hookHandlers;

@@ -10,0 +10,0 @@ constructor() {

@@ -1,4 +0,4 @@

import HooksManager from './hooks-manager';
import EventManager from './event-manager';
import StatsManager from './stats-manager';
import HooksManager from './hooks-manager.js';
import EventManager from './event-manager.js';
import StatsManager from './stats-manager.js';
export type DeserializedData<Value> = {

@@ -53,7 +53,7 @@ value?: Value;

/** The storage adapter instance to be used by Keyv. */
store?: KeyvStoreAdapter | Map<any, any>;
store?: KeyvStoreAdapter | Map<any, any> | any;
/** Default TTL. Can be overridden by specifying a TTL on `.set()`. */
ttl?: number;
/** Enable compression option **/
compression?: CompressionAdapter;
compression?: CompressionAdapter | any;
/** Enable or disable statistics (default is false) */

@@ -78,2 +78,3 @@ stats?: boolean;

_getKeyUnprefix(key: string): string;
_isValidStorageAdapter(store: KeyvStoreAdapter | any): boolean;
get<Value>(key: string, options?: {

@@ -80,0 +81,0 @@ raw: false;

@@ -8,5 +8,5 @@ "use strict";

const serialize_1 = require("@keyv/serialize");
const hooks_manager_1 = __importDefault(require("./hooks-manager"));
const event_manager_1 = __importDefault(require("./event-manager"));
const stats_manager_1 = __importDefault(require("./stats-manager"));
const hooks_manager_js_1 = __importDefault(require("./hooks-manager.js"));
const event_manager_js_1 = __importDefault(require("./event-manager.js"));
const stats_manager_js_1 = __importDefault(require("./stats-manager.js"));
var KeyvHooks;

@@ -31,7 +31,7 @@ (function (KeyvHooks) {

];
class Keyv extends event_manager_1.default {
class Keyv extends event_manager_js_1.default {
opts;
iterator;
hooks = new hooks_manager_1.default();
stats = new stats_manager_1.default(false);
hooks = new hooks_manager_js_1.default();
stats = new stats_manager_js_1.default(false);
constructor(store, options) {

@@ -54,3 +54,2 @@ super();

else {
// @ts-expect-error - Map is not a KeyvStoreAdapter
this.opts = {

@@ -67,2 +66,5 @@ ...this.opts,

if (this.opts.store) {
if (!this._isValidStorageAdapter(this.opts.store)) {
throw new Error('Invalid storage adapter');
}
if (typeof this.opts.store.on === 'function' && this.opts.emitErrors) {

@@ -105,3 +107,3 @@ this.opts.store.on('error', (error) => this.emit('error', error));

return iterableAdapters.includes(this.opts.store.opts.dialect)
|| iterableAdapters.findIndex(element => this.opts.store.opts.url.includes(element)) >= 0;
|| iterableAdapters.some(element => this.opts.store.opts.url.includes(element));
}

@@ -120,2 +122,8 @@ _getKeyPrefix(key) {

}
_isValidStorageAdapter(store) {
return (store instanceof Map || (typeof store.get === 'function'
&& typeof store.set === 'function'
&& typeof store.delete === 'function'
&& typeof store.clear === 'function'));
}
async get(key, options) {

@@ -122,0 +130,0 @@ const { store } = this.opts;

@@ -1,2 +0,2 @@

import EventManager from './event-manager';
import EventManager from './event-manager.js';
declare class StatsManager extends EventManager {

@@ -3,0 +3,0 @@ enabled: boolean;

@@ -6,4 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const event_manager_1 = __importDefault(require("./event-manager"));
class StatsManager extends event_manager_1.default {
const event_manager_js_1 = __importDefault(require("./event-manager.js"));
class StatsManager extends event_manager_js_1.default {
enabled = true;

@@ -10,0 +10,0 @@ hits = 0;

@@ -1,2 +0,2 @@

import EventManager from './event-manager';
import EventManager from './event-manager.js';
type HookHandler = (...arguments_: any[]) => void;

@@ -3,0 +3,0 @@ declare class HooksManager extends EventManager {

@@ -1,2 +0,2 @@

import EventManager from './event-manager';
import EventManager from './event-manager.js';
class HooksManager extends EventManager {

@@ -3,0 +3,0 @@ _hookHandlers;

@@ -1,4 +0,4 @@

import HooksManager from './hooks-manager';
import EventManager from './event-manager';
import StatsManager from './stats-manager';
import HooksManager from './hooks-manager.js';
import EventManager from './event-manager.js';
import StatsManager from './stats-manager.js';
export type DeserializedData<Value> = {

@@ -53,7 +53,7 @@ value?: Value;

/** The storage adapter instance to be used by Keyv. */
store?: KeyvStoreAdapter | Map<any, any>;
store?: KeyvStoreAdapter | Map<any, any> | any;
/** Default TTL. Can be overridden by specifying a TTL on `.set()`. */
ttl?: number;
/** Enable compression option **/
compression?: CompressionAdapter;
compression?: CompressionAdapter | any;
/** Enable or disable statistics (default is false) */

@@ -78,2 +78,3 @@ stats?: boolean;

_getKeyUnprefix(key: string): string;
_isValidStorageAdapter(store: KeyvStoreAdapter | any): boolean;
get<Value>(key: string, options?: {

@@ -80,0 +81,0 @@ raw: false;

import { defaultSerialize, defaultDeserialize } from '@keyv/serialize';
import HooksManager from './hooks-manager';
import EventManager from './event-manager';
import StatsManager from './stats-manager';
import HooksManager from './hooks-manager.js';
import EventManager from './event-manager.js';
import StatsManager from './stats-manager.js';
export var KeyvHooks;

@@ -46,3 +46,2 @@ (function (KeyvHooks) {

else {
// @ts-expect-error - Map is not a KeyvStoreAdapter
this.opts = {

@@ -59,2 +58,5 @@ ...this.opts,

if (this.opts.store) {
if (!this._isValidStorageAdapter(this.opts.store)) {
throw new Error('Invalid storage adapter');
}
if (typeof this.opts.store.on === 'function' && this.opts.emitErrors) {

@@ -97,3 +99,3 @@ this.opts.store.on('error', (error) => this.emit('error', error));

return iterableAdapters.includes(this.opts.store.opts.dialect)
|| iterableAdapters.findIndex(element => this.opts.store.opts.url.includes(element)) >= 0;
|| iterableAdapters.some(element => this.opts.store.opts.url.includes(element));
}

@@ -112,2 +114,8 @@ _getKeyPrefix(key) {

}
_isValidStorageAdapter(store) {
return (store instanceof Map || (typeof store.get === 'function'
&& typeof store.set === 'function'
&& typeof store.delete === 'function'
&& typeof store.clear === 'function'));
}
async get(key, options) {

@@ -114,0 +122,0 @@ const { store } = this.opts;

@@ -1,2 +0,2 @@

import EventManager from './event-manager';
import EventManager from './event-manager.js';
declare class StatsManager extends EventManager {

@@ -3,0 +3,0 @@ enabled: boolean;

@@ -1,2 +0,2 @@

import EventManager from './event-manager';
import EventManager from './event-manager.js';
class StatsManager extends EventManager {

@@ -3,0 +3,0 @@ enabled = true;

{
"name": "keyv",
"version": "5.0.0-rc.1",
"version": "5.0.0",
"description": "Simple key-value storage with support for multiple backends",

@@ -15,3 +15,3 @@ "main": "dist/cjs/index.js",

"scripts": {
"build": "tsc --project tsconfig.csj.json && tsc --project tsconfig.esm.json",
"build": "rm -rf dist && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
"prepare": "yarn build",

@@ -55,3 +55,17 @@ "test": "xo --fix && vitest run --coverage",

"cache",
"ttl"
"ttl",
"key-value",
"storage",
"backend",
"adapter",
"redis",
"mongodb",
"sqlite",
"mysql",
"postgresql",
"memory",
"node-cache",
"lru-cache",
"lru",
"cache-manager"
],

@@ -69,6 +83,5 @@ "author": "Jared Wray <me@jaredwray.com> (http://jaredwray.com)",

"@keyv/test-suite": "*",
"pify": "^5.0.0",
"timekeeper": "^2.3.1",
"tsd": "^0.31.0",
"xo": "^0.58.0"
"tsd": "^0.31.1",
"xo": "^0.59.3"
},

@@ -79,4 +92,5 @@ "tsd": {

"files": [
"dist"
"dist",
"LISCENCE"
]
}

@@ -1,6 +0,2 @@

<h1 align="center">
<img width="250" src="https://jaredwray.com/images/keyv.svg" alt="keyv">
<br>
<br>
</h1>
[<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv)

@@ -48,21 +44,46 @@ > Simple key-value storage with support for multiple backends

npm install --save @keyv/etcd
npm install --save @keyv/memcache
```
Create a new Keyv instance, passing your connection string if applicable. Keyv will automatically load the correct storage adapter.
First, create a new Keyv instance.
```js
const Keyv = require('keyv');
import Keyv from 'keyv';
```
// One of the following
const keyv = new Keyv();
const keyv = new Keyv('redis://user:pass@localhost:6379');
const keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname');
const keyv = new Keyv('sqlite://path/to/database.sqlite');
const keyv = new Keyv('postgresql://user:pass@localhost:5432/dbname');
const keyv = new Keyv('mysql://user:pass@localhost:3306/dbname');
const keyv = new Keyv('etcd://localhost:2379');
Once you have created your Keyv instance you can use it as a simple key-value store with `in-memory` by default. To use a storage adapter, create an instance of the adapter and pass it to the Keyv constructor. Here are some examples:
```js
// redis
import KeyvRedis from '@keyv/redis';
const keyv = new Keyv(new KeyvRedis('redis://user:pass@localhost:6379'));
```
You can also pass in a storage adapter with other options such as `ttl` and `namespace` (example using `sqlite`):
```js
//sqlite
import KeyvSqlite from '@keyv/sqlite';
const keyvSqlite = new KeyvSqlite('sqlite://path/to/database.sqlite');
const keyv = new Keyv({ store: keyvSqlite, ttl: 5000, namespace: 'cache' });
```
To handle an event you can do the following:
```js
// Handle DB connection errors
keyv.on('error', err => console.log('Connection Error', err));
```
Now lets do an end-to-end example using `Keyv` and the `Redis` storage adapter:
```js
import Keyv from 'keyv';
import KeyvRedis from '@keyv/redis';
const keyvRedis = new KeyvRedis('redis://user:pass@localhost:6379');
const keyv = new Keyv({ store: keyvRedis });
await keyv.set('foo', 'expires in 1 second', 1000); // true

@@ -75,2 +96,4 @@ await keyv.set('foo', 'never expires'); // true

It's is just that simple! Keyv is designed to be simple and easy to use.
### Namespaces

@@ -81,4 +104,4 @@

```js
const users = new Keyv('redis://user:pass@localhost:6379', { namespace: 'users' });
const cache = new Keyv('redis://user:pass@localhost:6379', { namespace: 'cache' });
const users = new Keyv(new KeyvRedis('redis://user:pass@localhost:6379'), { namespace: 'users' });
const cache = new Keyv(new KeyvRedis('redis://user:pass@localhost:6379'), { namespace: 'cache' });

@@ -157,3 +180,3 @@ await users.set('foo', 'users'); // true

Keyv uses [`buffer`](https://github.com/feross/buffer) for data serialization to ensure consistency across different backends.
Keyv uses [`buffer`](https://nodejs.org/api/buffer.html) for data serialization to ensure consistency across different backends.

@@ -187,4 +210,4 @@ You can optionally provide your own serialization functions to support extra data types or to serialize to something other than JSON.

```js
const Keyv = require('keyv');
const myAdapter = require('./my-storage-adapter');
import Keyv from 'keyv';
import myAdapter from 'my-adapter';

@@ -203,4 +226,4 @@ const keyv = new Keyv({ store: myAdapter });

```js
const Keyv = require('keyv');
const QuickLRU = require('quick-lru');
import Keyv from 'keyv';
import QuickLRU from 'quick-lru';

@@ -247,3 +270,3 @@ const lru = new QuickLRU({ maxSize: 1000 });

```js
const AwesomeModule = require('awesome-module');
import AwesomeModule from 'awesome-module';

@@ -265,4 +288,4 @@ // Caches stuff in memory by default

```js
const KeyvGzip = require('@keyv/compress-gzip');
const Keyv = require('keyv');
import Keyv from 'keyv';
import KeyvGzip from '@keyv/compress-gzip';

@@ -291,4 +314,4 @@ const keyvGzip = new KeyvGzip();

```js
const {keyvCompresstionTests} = require('@keyv/test-suite');
const KeyvGzip = require('@keyv/compress-gzip');
import { keyvCompresstionTests } from '@keyv/test-suite';
import KeyvGzip from '@keyv/compress-gzip';

@@ -300,3 +323,3 @@ keyvCompresstionTests(test, new KeyvGzip());

### new Keyv([uri], [options])
### new Keyv([storage-adapter], [options]) or new Keyv([options])

@@ -307,5 +330,5 @@ Returns a new Keyv instance.

### uri
### storage-adapter
Type: `String`<br>
Type: `KeyvStorageAdapter`<br />
Default: `undefined`

@@ -325,3 +348,3 @@

Type: `String`<br>
Type: `String`<br />
Default: `'keyv'`

@@ -333,3 +356,3 @@

Type: `Number`<br>
Type: `Number`<br />
Default: `undefined`

@@ -341,3 +364,3 @@

Type: `@keyv/compress-<compression_package_name>`<br>
Type: `@keyv/compress-<compression_package_name>`<br />
Default: `undefined`

@@ -349,3 +372,3 @@

Type: `Function`<br>
Type: `Function`<br />
Default: `JSONB.stringify`

@@ -357,3 +380,3 @@

Type: `Function`<br>
Type: `Function`<br />
Default: `JSONB.parse`

@@ -365,3 +388,3 @@

Type: `Storage adapter instance`<br>
Type: `Storage adapter instance`<br />
Default: `new Map()`

@@ -371,9 +394,2 @@

#### options.adapter
Type: `String`<br>
Default: `undefined`
Specify an adapter to use. e.g `'redis'` or `'mongodb'`.
### Instance

@@ -397,3 +413,3 @@

Type: `Boolean`<br>
Type: `Boolean`<br />
Default: `false`

@@ -432,79 +448,10 @@

In this section of the documentation we will cover:
We welcome contributions to Keyv! 🎉 Here are some guides to get you started with contributing:
1) How to set up this repository locally
2) How to get started with running commands
3) How to contribute changes using Pull Requests
* [Contributing](https://github.com/jaredwray/keyv/blob/main/CONTRIBUTING.md) - Learn about how to contribute to Keyv
* [Code of Conduct](https://github.com/jaredwray/keyv/blob/main/CODE_OF_CONDUCT.md) - Learn about the Keyv Code of Conduct
* [How to Contribute](https://github.com/jaredwray/keyv/blob/main/README.md) - How do develop in the Keyv mono repo!
## Dependencies
# License
This package requires the following dependencies to run:
1) [Yarn V1](https://yarnpkg.com/getting-started/install)
3) [Docker](https://docs.docker.com/get-docker/)
## Setting up your workspace
To contribute to this repository, start by setting up this project locally:
1) Fork this repository into your Git account
2) Clone the forked repository to your local directory using `git clone`
3) Install any of the above missing dependencies
## Launching the project
Once the project is installed locally, you are ready to start up its services:
1) Ensure that your Docker service is running.
2) From the root directory of your project, run the `yarn` command in the command prompt to install yarn.
3) Run the `yarn bootstrap` command to install any necessary dependencies.
4) Run `yarn test:services:start` to start up this project's Docker container. The container will launch all services within your workspace.
## Available Commands
Once the project is running, you can execute a variety of commands. The root workspace and each subpackage contain a `package.json` file with a `scripts` field listing all the commands that can be executed from that directory. This project also supports native `yarn`, and `docker` commands.
Here, we'll cover the primary commands that can be executed from the root directory. Unless otherwise noted, these commands can also be executed from a subpackage. If executed from a subpackage, they will only affect that subpackage, rather than the entire workspace.
### `yarn`
The `yarn` command installs yarn in the workspace.
### `yarn bootstrap`
The `yarn bootstrap` command installs all dependencies in the workspace.
### `yarn test:services:start`
The `yarn test:services:start` command starts up the project's Docker container, launching all services in the workspace. This command must be executed from the root directory.
### `yarn test:services:stop`
The `yarn test:services:stop` command brings down the project's Docker container, halting all services. This command must be executed from the root directory.
### `yarn test`
The `yarn test` command runs all tests in the workspace.
### `yarn clean`
The `yarn clean` command removes yarn and all dependencies installed by yarn. After executing this command, you must repeat the steps in *Setting up your workspace* to rebuild your workspace.
## Contributing Changes
Now that you've set up your workspace, you're ready to contribute changes to the `keyv` repository.
1) Make any changes that you would like to contribute in your local workspace.
2) After making these changes, ensure that the project's tests still pass by executing the `yarn test` command in the root directory.
3) Commit your changes and push them to your forked repository.
4) Navigate to the original `keyv` repository and go the *Pull Requests* tab.
5) Click the *New pull request* button, and open a pull request for the branch in your repository that contains your changes.
6) Once your pull request is created, ensure that all checks have passed and that your branch has no conflicts with the base branch. If there are any issues, resolve these changes in your local repository, and then commit and push them to git.
7) Similarly, respond to any reviewer comments or requests for changes by making edits to your local repository and pushing them to Git.
8) Once the pull request has been reviewed, those with write access to the branch will be able to merge your changes into the `keyv` repository.
If you need more information on the steps to create a pull request, you can find a detailed walkthrough in the [Github documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork)
## License
MIT © Jared Wray
[MIT © Jared Wray](LICENSE)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc