Skip to content

Commit

Permalink
Types
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovepixelart committed May 9, 2024
1 parent 72e2ae5 commit 26e8a4b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cache/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CacheEngine {
return cacheEntry
}

async set(key: string, value: Record<string, unknown> | Record<string, unknown>[], ttl: string | null): Promise<void> {
async set(key: string, value: IData, ttl: string | null): Promise<void> {
const actualTTL = ttl ? ms(ttl) : this.#defaultTTL
await this.#engine.set(key, value, actualTTL)
if (this.#debug) {
Expand Down
2 changes: 1 addition & 1 deletion src/cache/engine/RedisCacheEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RedisCacheEngine implements ICacheEngine {
return EJSON.parse(value) as Promise<Record<string, unknown> | Record<string, unknown>[]>
}

async set(key: string, value: unknown, ttl = Infinity): Promise<void> {
async set(key: string, value: IData, ttl = Infinity): Promise<void> {
const serializedValue = EJSON.stringify(convertToObject(value))
await this.#client.setex(key, Math.ceil(ttl / 1000), serializedValue)
}
Expand Down
3 changes: 2 additions & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { satisfies } from 'semver'
import mongoose from 'mongoose'
import type IData from './interfaces/IData'

export const isMongooseLessThan7 = satisfies(mongoose.version, '<7')

export const convertToObject = (value: unknown): unknown => {
export const convertToObject = <T>(value: T & { toObject?: () => IData } | undefined): IData => {
if (isMongooseLessThan7) {
if (value != null && typeof value === 'object' && !Array.isArray(value) && value.toObject) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
Expand Down

0 comments on commit 26e8a4b

Please sign in to comment.