From 0136b6aae00ae5c459d1a4cede21f5a1b9fcd78a Mon Sep 17 00:00:00 2001 From: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:45:07 -0400 Subject: [PATCH] feat: awaitable type --- src/cache/adapters/types.ts | 48 ++++++++++++++++++------------------- src/common/types/util.ts | 2 ++ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/cache/adapters/types.ts b/src/cache/adapters/types.ts index 137bfa0..3f0c47b 100644 --- a/src/cache/adapters/types.ts +++ b/src/cache/adapters/types.ts @@ -1,41 +1,41 @@ +import type { Awaitable } from '../../common'; + export interface Adapter { isAsync: boolean; - scan(query: string, keys?: false): RPV; - scan(query: string, keys: true): RPV; - scan(query: string, keys?: boolean): RPV<(any | string)[]>; + scan(query: string, keys?: false): Awaitable; + scan(query: string, keys: true): Awaitable; + scan(query: string, keys?: boolean): Awaitable<(any | string)[]>; - get(keys: string[]): RPV; - get(keys: string): RPV; - get(keys: string | string[]): RPV; + get(keys: string[]): Awaitable; + get(keys: string): Awaitable; + get(keys: string | string[]): Awaitable; - set(keyValue: [string, any][]): RPV; - set(id: string, data: any): RPV; - set(id: string | [string, any][], data?: any): RPV; + set(keyValue: [string, any][]): Awaitable; + set(id: string, data: any): Awaitable; + set(id: string | [string, any][], data?: any): Awaitable; - patch(updateOnly: boolean, keyValue: [string, any][]): RPV; - patch(updateOnly: boolean, id: string, data: any): RPV; - patch(updateOnly: boolean, id: string | [string, any][], data?: any): RPV; + patch(updateOnly: boolean, keyValue: [string, any][]): Awaitable; + patch(updateOnly: boolean, id: string, data: any): Awaitable; + patch(updateOnly: boolean, id: string | [string, any][], data?: any): Awaitable; - values(to: string): RPV; + values(to: string): Awaitable; - keys(to: string): RPV; + keys(to: string): Awaitable; - count(to: string): RPV; + count(to: string): Awaitable; - remove(keys: string | string[]): RPV; + remove(keys: string | string[]): Awaitable; - contains(to: string, keys: string): RPV; + contains(to: string, keys: string): Awaitable; - getToRelationship(to: string): RPV; + getToRelationship(to: string): Awaitable; - bulkAddToRelationShip(data: Record): RPV; + bulkAddToRelationShip(data: Record): Awaitable; - addToRelationship(to: string, keys: string | string[]): RPV; + addToRelationship(to: string, keys: string | string[]): Awaitable; - removeToRelationship(to: string, keys: string | string[]): RPV; + removeToRelationship(to: string, keys: string | string[]): Awaitable; - removeRelationship(to: string | string[]): RPV; + removeRelationship(to: string | string[]): Awaitable; } - -export type RPV = Promise | V; diff --git a/src/common/types/util.ts b/src/common/types/util.ts index edace6b..59de584 100644 --- a/src/common/types/util.ts +++ b/src/common/types/util.ts @@ -190,3 +190,5 @@ export type FlatObjectKeys, Key = keyof T> = Key e ? `${Key}` : never : never; + +export type Awaitable = Promise | V;