From 73e779a115f38dcfd7958c85785b4cd1932487e7 Mon Sep 17 00:00:00 2001 From: Rossb0b Date: Fri, 7 Feb 2025 16:32:20 +0100 Subject: [PATCH] refactor(./class/store/transaction.class.ts): use of TimedKVPeer --- src/class/store/transaction.class.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/class/store/transaction.class.ts b/src/class/store/transaction.class.ts index 44f53e3..8171079 100644 --- a/src/class/store/transaction.class.ts +++ b/src/class/store/transaction.class.ts @@ -3,9 +3,9 @@ import { randomUUID } from "node:crypto"; // Import Third-party Dependencies import { - KVOptions, - KVPeer, RedisAdapter, + TimedKVPeer, + TimedKVPeerOptions, Types } from "@myunisoft/redis"; @@ -19,6 +19,10 @@ import type { DistributedEventMessage, Instance } from "../../types/index.js"; + +// CONSTANTS +const kDefaultTTL = 60_000 * 60 * 24; + type BaseTransaction< IsMain extends boolean = true, RelatedTransaction = IsMain extends true ? null : string @@ -97,15 +101,15 @@ export type Transactions = Map>; export type TransactionStoreOptions< T extends Instance -> = (Partial>> & +> = (Omit>, "prefix" | "adapter"> & ( T extends "incomer" ? { prefix: string; } : { prefix?: string; }) & { adapter: Types.DatabaseConnection; instance: T; -}; +}); export class TransactionStore< T extends Instance = Instance -> extends KVPeer< +> extends TimedKVPeer< Transaction, null, RedisAdapter @@ -117,10 +121,12 @@ export class TransactionStore< ) { super({ ...options, - prefix: undefined, - type: "object" + ttl: options.ttl ?? kDefaultTTL, + mapValue: undefined, + prefix: undefined }); + this.#key = `${options.prefix ? `${options.prefix}-` : ""}${options.instance}-transaction`; }