import { SessionInterface } from "./session.interface.ts";import { SessionStore } from "./store/store.interface.ts";import { generate } from "https://deno.land/std@0.171.0/uuid/v1.ts";import { getHash } from "./session.utils.ts";
export class Session implements SessionInterface { public readonly sessionIdHash: Uint8Array;
constructor( public readonly store: SessionStore, public readonly sessionKey: string, public readonly sessionId: string = generate().toString(), ) { this.sessionIdHash = getHash(this.sessionId); }
get<T>(key: string): Promise<T> { return this.store.getValue(this.sessionId, key); }
set<T>(key: string, value: T): Promise<void> { return this.store.setValue(this.sessionId, key, value); }}