From e7b53641d7ca6dce6cd123d5b4da316e0399a418 Mon Sep 17 00:00:00 2001 From: renovate <29139614+renovate@users.noreply.github.com> Date: Tue, 3 Sep 2024 09:37:39 +0000 Subject: [PATCH] chore: bump up keyv version to v5 (#7936) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- - [ ] 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). --- packages/backend/server/package.json | 2 +- .../server/src/fundamentals/cache/local.ts | 30 +++++++++++-------- yarn.lock | 6 ++-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/backend/server/package.json b/packages/backend/server/package.json index 49d9026702..9a705b08df 100644 --- a/packages/backend/server/package.json +++ b/packages/backend/server/package.json @@ -70,7 +70,7 @@ "graphql-upload": "^16.0.2", "html-validate": "^8.20.1", "ioredis": "^5.3.2", - "keyv": "^4.5.4", + "keyv": "^5.0.0", "lodash-es": "^4.17.21", "mixpanel": "^0.18.0", "mustache": "^4.2.0", diff --git a/packages/backend/server/src/fundamentals/cache/local.ts b/packages/backend/server/src/fundamentals/cache/local.ts index 6e6ac148ac..ca46e17bd3 100644 --- a/packages/backend/server/src/fundamentals/cache/local.ts +++ b/packages/backend/server/src/fundamentals/cache/local.ts @@ -1,17 +1,17 @@ -import Keyv from 'keyv'; +import Keyv, { KeyvOptions } from 'keyv'; import type { Cache, CacheSetOptions } from './def'; export class LocalCache implements Cache { private readonly kv: Keyv; - constructor(opts: Keyv.Options = {}) { + constructor(opts: KeyvOptions = {}) { this.kv = new Keyv(opts); } // standard operation async get(key: string): Promise { - return this.kv.get(key).catch(() => undefined); + return this.kv.get(key).catch(() => undefined); } async set( @@ -74,14 +74,14 @@ export class LocalCache implements Cache { // list operations private async getArray(key: string) { - const raw = await this.kv.get(key, { raw: true }); + const raw = await this.kv.get(key, { raw: true }); if (raw && !Array.isArray(raw.value)) { throw new Error( `Expect an Array keyed by ${key}, but found ${raw.value}` ); } - return raw as Keyv.DeserializedData; + return raw; } private async setArray( @@ -97,7 +97,9 @@ export class LocalCache implements Cache { let ttl: number | undefined = undefined; const raw = await this.getArray(key); if (raw) { - list = raw.value; + if (raw.value) { + list = raw.value; + } if (raw.expires) { ttl = raw.expires - Date.now(); } @@ -112,7 +114,9 @@ export class LocalCache implements Cache { let ttl: number | undefined = undefined; const raw = await this.getArray(key); if (raw) { - list = raw.value; + if (raw.value) { + list = raw.value; + } if (raw.expires) { ttl = raw.expires - Date.now(); } @@ -123,7 +127,7 @@ export class LocalCache implements Cache { } async len(key: string): Promise { - return this.getArray(key).then(v => v?.value.length ?? 0); + return this.getArray(key).then(v => v?.value?.length ?? 0); } /** @@ -147,7 +151,7 @@ export class LocalCache implements Cache { private async trim(key: string, start: number, end: number) { const raw = await this.getArray(key); - if (raw) { + if (raw && raw.value) { start = (raw.value.length + start) % raw.value.length; // make negative end index work, and end indice is inclusive end = ((raw.value.length + end) % raw.value.length) + 1; @@ -173,7 +177,7 @@ export class LocalCache implements Cache { // map operations private async getMap(map: string) { - const raw = await this.kv.get(map, { raw: true }); + const raw = await this.kv.get>(map, { raw: true }); if (raw) { if (typeof raw.value !== 'object') { @@ -187,7 +191,7 @@ export class LocalCache implements Cache { } } - return raw as Keyv.DeserializedData>; + return raw; } private async setMap( @@ -263,7 +267,7 @@ export class LocalCache implements Cache { async mapKeys(map: string): Promise { const raw = await this.getMap(map); - if (raw) { + if (raw?.value) { return Object.keys(raw.value); } @@ -277,6 +281,6 @@ export class LocalCache implements Cache { async mapLen(map: string): Promise { const raw = await this.getMap(map); - return raw ? Object.keys(raw.value).length : 0; + return raw?.value ? Object.keys(raw.value).length : 0; } } diff --git a/yarn.lock b/yarn.lock index ecdb5d0195..fb153283c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -868,7 +868,7 @@ __metadata: graphql-upload: "npm:^16.0.2" html-validate: "npm:^8.20.1" ioredis: "npm:^5.3.2" - keyv: "npm:^4.5.4" + keyv: "npm:^5.0.0" lodash-es: "npm:^4.17.21" mixpanel: "npm:^0.18.0" mustache: "npm:^4.2.0" @@ -25637,7 +25637,7 @@ __metadata: languageName: node linkType: hard -"keyv@npm:*": +"keyv@npm:*, keyv@npm:^5.0.0": version: 5.0.1 resolution: "keyv@npm:5.0.1" dependencies: @@ -25646,7 +25646,7 @@ __metadata: languageName: node 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 resolution: "keyv@npm:4.5.4" dependencies: