chore: bump up keyv version to v5 (#7936)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [keyv](https://togithub.com/jaredwray/keyv) | [`^4.5.4` -> `^5.0.0`](https://renovatebot.com/diffs/npm/keyv/4.5.4/5.0.1) | [![age](https://developer.mend.io/api/mc/badges/age/npm/keyv/5.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/keyv/5.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/keyv/4.5.4/5.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/keyv/4.5.4/5.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/toeverything/AFFiNE).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNi4xIiwidXBkYXRlZEluVmVyIjoiMzguNTYuMCIsInRhcmdldEJyYW5jaCI6ImNhbmFyeSIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->
This commit is contained in:
renovate
2024-09-03 09:37:39 +00:00
parent 41f9149be6
commit e7b53641d7
3 changed files with 21 additions and 17 deletions

View File

@@ -70,7 +70,7 @@
"graphql-upload": "^16.0.2", "graphql-upload": "^16.0.2",
"html-validate": "^8.20.1", "html-validate": "^8.20.1",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
"keyv": "^4.5.4", "keyv": "^5.0.0",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"mixpanel": "^0.18.0", "mixpanel": "^0.18.0",
"mustache": "^4.2.0", "mustache": "^4.2.0",

View File

@@ -1,17 +1,17 @@
import Keyv from 'keyv'; import Keyv, { KeyvOptions } from 'keyv';
import type { Cache, CacheSetOptions } from './def'; import type { Cache, CacheSetOptions } from './def';
export class LocalCache implements Cache { export class LocalCache implements Cache {
private readonly kv: Keyv; private readonly kv: Keyv;
constructor(opts: Keyv.Options<any> = {}) { constructor(opts: KeyvOptions = {}) {
this.kv = new Keyv(opts); this.kv = new Keyv(opts);
} }
// standard operation // standard operation
async get<T = unknown>(key: string): Promise<T | undefined> { async get<T = unknown>(key: string): Promise<T | undefined> {
return this.kv.get(key).catch(() => undefined); return this.kv.get<T>(key).catch(() => undefined);
} }
async set<T = unknown>( async set<T = unknown>(
@@ -74,14 +74,14 @@ export class LocalCache implements Cache {
// list operations // list operations
private async getArray<T = unknown>(key: string) { private async getArray<T = unknown>(key: string) {
const raw = await this.kv.get(key, { raw: true }); const raw = await this.kv.get<T[]>(key, { raw: true });
if (raw && !Array.isArray(raw.value)) { if (raw && !Array.isArray(raw.value)) {
throw new Error( throw new Error(
`Expect an Array keyed by ${key}, but found ${raw.value}` `Expect an Array keyed by ${key}, but found ${raw.value}`
); );
} }
return raw as Keyv.DeserializedData<T[]>; return raw;
} }
private async setArray<T = unknown>( private async setArray<T = unknown>(
@@ -97,7 +97,9 @@ export class LocalCache implements Cache {
let ttl: number | undefined = undefined; let ttl: number | undefined = undefined;
const raw = await this.getArray(key); const raw = await this.getArray(key);
if (raw) { if (raw) {
list = raw.value; if (raw.value) {
list = raw.value;
}
if (raw.expires) { if (raw.expires) {
ttl = raw.expires - Date.now(); ttl = raw.expires - Date.now();
} }
@@ -112,7 +114,9 @@ export class LocalCache implements Cache {
let ttl: number | undefined = undefined; let ttl: number | undefined = undefined;
const raw = await this.getArray(key); const raw = await this.getArray(key);
if (raw) { if (raw) {
list = raw.value; if (raw.value) {
list = raw.value;
}
if (raw.expires) { if (raw.expires) {
ttl = raw.expires - Date.now(); ttl = raw.expires - Date.now();
} }
@@ -123,7 +127,7 @@ export class LocalCache implements Cache {
} }
async len(key: string): Promise<number> { async len(key: string): Promise<number> {
return this.getArray(key).then(v => v?.value.length ?? 0); return this.getArray<any[]>(key).then(v => v?.value?.length ?? 0);
} }
/** /**
@@ -147,7 +151,7 @@ export class LocalCache implements Cache {
private async trim<T = unknown>(key: string, start: number, end: number) { private async trim<T = unknown>(key: string, start: number, end: number) {
const raw = await this.getArray<T>(key); const raw = await this.getArray<T>(key);
if (raw) { if (raw && raw.value) {
start = (raw.value.length + start) % raw.value.length; start = (raw.value.length + start) % raw.value.length;
// make negative end index work, and end indice is inclusive // make negative end index work, and end indice is inclusive
end = ((raw.value.length + end) % raw.value.length) + 1; end = ((raw.value.length + end) % raw.value.length) + 1;
@@ -173,7 +177,7 @@ export class LocalCache implements Cache {
// map operations // map operations
private async getMap<T = unknown>(map: string) { private async getMap<T = unknown>(map: string) {
const raw = await this.kv.get(map, { raw: true }); const raw = await this.kv.get<Record<string, T>>(map, { raw: true });
if (raw) { if (raw) {
if (typeof raw.value !== 'object') { if (typeof raw.value !== 'object') {
@@ -187,7 +191,7 @@ export class LocalCache implements Cache {
} }
} }
return raw as Keyv.DeserializedData<Record<string, T>>; return raw;
} }
private async setMap<T = unknown>( private async setMap<T = unknown>(
@@ -263,7 +267,7 @@ export class LocalCache implements Cache {
async mapKeys(map: string): Promise<string[]> { async mapKeys(map: string): Promise<string[]> {
const raw = await this.getMap(map); const raw = await this.getMap(map);
if (raw) { if (raw?.value) {
return Object.keys(raw.value); return Object.keys(raw.value);
} }
@@ -277,6 +281,6 @@ export class LocalCache implements Cache {
async mapLen(map: string): Promise<number> { async mapLen(map: string): Promise<number> {
const raw = await this.getMap(map); const raw = await this.getMap(map);
return raw ? Object.keys(raw.value).length : 0; return raw?.value ? Object.keys(raw.value).length : 0;
} }
} }

View File

@@ -868,7 +868,7 @@ __metadata:
graphql-upload: "npm:^16.0.2" graphql-upload: "npm:^16.0.2"
html-validate: "npm:^8.20.1" html-validate: "npm:^8.20.1"
ioredis: "npm:^5.3.2" ioredis: "npm:^5.3.2"
keyv: "npm:^4.5.4" keyv: "npm:^5.0.0"
lodash-es: "npm:^4.17.21" lodash-es: "npm:^4.17.21"
mixpanel: "npm:^0.18.0" mixpanel: "npm:^0.18.0"
mustache: "npm:^4.2.0" mustache: "npm:^4.2.0"
@@ -25637,7 +25637,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"keyv@npm:*": "keyv@npm:*, keyv@npm:^5.0.0":
version: 5.0.1 version: 5.0.1
resolution: "keyv@npm:5.0.1" resolution: "keyv@npm:5.0.1"
dependencies: dependencies:
@@ -25646,7 +25646,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"keyv@npm:^4.0.0, keyv@npm:^4.5.3, keyv@npm:^4.5.4": "keyv@npm:^4.0.0, keyv@npm:^4.5.3":
version: 4.5.4 version: 4.5.4
resolution: "keyv@npm:4.5.4" resolution: "keyv@npm:4.5.4"
dependencies: dependencies: