import type { Result } from '@byteslice/result' import type { ProtectError } from '../..' export type AuditConfig = { metadata?: Record } export type AuditData = { metadata?: Record } export abstract class ProtectOperation { protected auditMetadata?: Record /** * Attach audit metadata to this operation. Can be chained. * @param config Configuration for ZeroKMS audit logging * @param config.metadata Arbitrary JSON object for appending metadata to the audit log */ audit(config: AuditConfig): this { this.auditMetadata = config.metadata return this } /** * Get the audit data for this operation. */ public getAuditData(): AuditData { return { metadata: this.auditMetadata, } } /** * Execute the operation and return a Result */ abstract execute(): Promise> /** * Make the operation thenable */ public then, TResult2 = never>( onfulfilled?: | ((value: Result) => TResult1 | PromiseLike) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike) | null, ): Promise { return this.execute().then(onfulfilled, onrejected) } }