Skip to content

Commit

Permalink
fix: fixing some type issues, and improve keys, pagination methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vwh committed Nov 5, 2024
1 parent fff1382 commit c4dae60
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export abstract class BaseMiftahDB implements IMiftahDB {

@SafeExecution
get<T>(key: string): Result<T> {
const result = this.statements.get.get(this.addNamespacePrefix(key)) as
| MiftahDBItem
| undefined;
const result = this.statements.get.get(
this.addNamespacePrefix(key)
) as MiftahDBItem | null;

if (!result) throw Error("Key not found");
if (result.expires_at && result.expires_at <= Date.now()) {
Expand Down Expand Up @@ -142,11 +142,9 @@ export abstract class BaseMiftahDB implements IMiftahDB {
getExpire(key: string): Result<Date> {
const result = this.statements.getExpire.get(
this.addNamespacePrefix(key)
) as
| {
expires_at: number | null;
}
| undefined;
) as {
expires_at: number | null;
} | null;

if (!result) throw Error("Key not found");
if (!result.expires_at) throw Error("Key has no expiration");
Expand All @@ -162,8 +160,8 @@ export abstract class BaseMiftahDB implements IMiftahDB {
key: string;
}[];

if (result.length === 0) throw Error("No keys found");
const resultArray = result.map((r) => this.removeNamespacePrefix(r.key));
if (resultArray.length === 0) throw Error("No keys found");

return {
success: true,
Expand All @@ -180,8 +178,8 @@ export abstract class BaseMiftahDB implements IMiftahDB {
offset
) as { key: string }[];

if (result.length === 0) throw Error("No keys found");
const resultArray = result.map((r) => this.removeNamespacePrefix(r.key));
if (resultArray.length === 0) throw Error("No keys found");

return {
success: true,
Expand Down

0 comments on commit c4dae60

Please sign in to comment.