keyv
Advanced tools
Comparing version 4.5.4 to 5.0.0-rc.1
{ | ||
"name": "keyv", | ||
"version": "4.5.4", | ||
"version": "5.0.0-rc.1", | ||
"description": "Simple key-value storage with support for multiple backends", | ||
"main": "src/index.js", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/esm/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/cjs/index.js", | ||
"import": "./dist/esm/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"build": "echo 'No build step required.'", | ||
"build": "tsc --project tsconfig.csj.json && tsc --project tsconfig.esm.json", | ||
"prepare": "yarn build", | ||
"test": "xo && c8 ava --serial", | ||
"test:ci": "xo && ava --serial", | ||
"clean": "rm -rf node_modules && rm -rf ./coverage && rm -rf ./test/testdb.sqlite" | ||
"test": "xo --fix && vitest run --coverage", | ||
"test:ci": "xo && vitest --run --sequence.setupFiles=list", | ||
"clean": "rm -rf node_modules && rm -rf ./coverage && rm -rf ./test/testdb.sqlite && rm -rf ./dist" | ||
}, | ||
"xo": { | ||
"rules": { | ||
"unicorn/prefer-module": 0, | ||
"unicorn/prefer-node-protocol": 0, | ||
"@typescript-eslint/consistent-type-definitions": 0, | ||
"unicorn/no-typeof-undefined": 0, | ||
"unicorn/prefer-event-target": 0 | ||
"unicorn/prefer-module": "off", | ||
"unicorn/prefer-node-protocol": "off", | ||
"@typescript-eslint/consistent-type-definitions": "off", | ||
"unicorn/no-typeof-undefined": "off", | ||
"unicorn/prefer-event-target": "off", | ||
"import/no-extraneous-dependencies": "off", | ||
"import/extensions": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-for-in-array": "off", | ||
"guard-for-in": "off", | ||
"no-await-in-loop": "off", | ||
"@typescript-eslint/no-unsafe-return": "off", | ||
"@typescript-eslint/no-unsafe-assignment": "off", | ||
"@typescript-eslint/no-unsafe-argument": "off", | ||
"@typescript-eslint/naming-convention": "off", | ||
"@typescript-eslint/consistent-type-assertions": "off", | ||
"@typescript-eslint/no-confusing-void-expression": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/prefer-ts-expect-error": "off" | ||
} | ||
@@ -40,11 +63,10 @@ }, | ||
"dependencies": { | ||
"json-buffer": "3.0.1" | ||
"@keyv/serialize": "*" | ||
}, | ||
"devDependencies": { | ||
"@keyv/test-suite": "*", | ||
"eslint": "^8.51.0", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"pify": "^5.0.0", | ||
"timekeeper": "^2.3.1", | ||
"tsd": "^0.29.0" | ||
"tsd": "^0.31.0", | ||
"xo": "^0.58.0" | ||
}, | ||
@@ -54,6 +76,5 @@ "tsd": { | ||
}, | ||
"types": "./src/index.d.ts", | ||
"files": [ | ||
"src" | ||
"dist" | ||
] | ||
} |
@@ -91,5 +91,66 @@ <h1 align="center"> | ||
### Events | ||
Keyv is a custom `EventEmitter` and will emit an `'error'` event if there is an error. In addition it will emit a `clear` and `disconnect` event when the corresponding methods are called. | ||
```js | ||
const keyv = new Keyv(); | ||
const handleConnectionError = err => console.log('Connection Error', err); | ||
const handleClear = () => console.log('Cache Cleared'); | ||
const handleDisconnect = () => console.log('Disconnected'); | ||
keyv.on('error', handleConnectionError); | ||
keyv.on('clear', handleClear); | ||
keyv.on('disconnect', handleDisconnect); | ||
``` | ||
### Hooks | ||
Keyv supports hooks for `get`, `set`, and `delete` methods. Hooks are useful for logging, debugging, and other custom functionality. Here is a list of all the hooks: | ||
``` | ||
PRE_GET | ||
POST_GET | ||
PRE_GET_MANY | ||
POST_GET_MANY | ||
PRE_SET | ||
POST_SET | ||
PRE_DELETE | ||
POST_DELETE | ||
``` | ||
You can access this by importing `KeyvHooks` from the main Keyv package. | ||
```js | ||
import Keyv, { KeyvHooks } from 'keyv'; | ||
``` | ||
```js | ||
//PRE_SET hook | ||
const keyv = new Keyv(); | ||
keyv.hooks.addListener(KeyvHooks.PRE_SET, (key, value) => console.log(`Setting key ${key} to ${value}`)); | ||
//POST_SET hook | ||
const keyv = new Keyv(); | ||
keyv.hooks.addListener(KeyvHooks.POST_SET, (key, value) => console.log(`Set key ${key} to ${value}`)); | ||
``` | ||
In these examples you can also manipulate the value before it is set. For example, you could add a prefix to all keys. | ||
```js | ||
const keyv = new Keyv(); | ||
keyv.hooks.addListener(KeyvHooks.PRE_SET, (key, value) => { | ||
console.log(`Setting key ${key} to ${value}`); | ||
key = `prefix-${key}`; | ||
}); | ||
``` | ||
Now this key will have prefix- added to it before it is set. | ||
In `PRE_DELETE` and `POST_DELETE` hooks, the value could be a single item or an `Array`. This is based on the fact that `delete` can accept a single key or an `Array` of keys. | ||
### Custom Serializers | ||
Keyv uses [`json-buffer`](https://github.com/dominictarr/json-buffer) for data serialization to ensure consistency across different backends. | ||
Keyv uses [`buffer`](https://github.com/feross/buffer) for data serialization to ensure consistency across different backends. | ||
@@ -96,0 +157,0 @@ You can optionally provide your own serialization functions to support extra data types or to serialize to something other than JSON. |
Floating dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
93735
5
26
1170
491
0
1
1
1
+ Added@keyv/serialize@*
- Removedjson-buffer@3.0.1
- Removedjson-buffer@3.0.1(transitive)