// @bun
var{defineProperty:E,getOwnPropertyNames:G,getOwnPropertyDescriptor:H}=Object,J=Object.prototype.hasOwnProperty;function K(j){return this[j]}var P=(j)=>{var q=(F??=new WeakMap).get(j),z;if(q)return q;if(q=E({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var A of G(j))if(!J.call(q,A))E(q,A,{get:K.bind(j,A),enumerable:!(z=H(j,A))||z.enumerable})}return F.set(j,q),q},F;var L=(j)=>j;function M(j,q){this[j]=L.bind(null,q)}var Q=(j,q)=>{for(var z in q)E(j,z,{get:q[z],enumerable:!0,configurable:!0,set:M.bind(q,z)})};var R=(j,q)=>()=>(j&&(q=j(j=0)),q);function B(j){return{...j,data:D(j.data),history:j.history.map((q)=>({...q,input:D(q.input),output:D(q.output),startedAt:new Date(q.startedAt),completedAt:q.completedAt?new Date(q.completedAt):void 0})),createdAt:new Date(j.createdAt),updatedAt:new Date(j.updatedAt)}}class O{items=new Map;async create(j){if(this.items.has(j.workflowId))throw Error(`Workflow state already exists: ${j.workflowId}`);this.items.set(j.workflowId,B(j))}async get(j){let q=this.items.get(j);return q?B(q):void 0}async update(j,q){let z=this.items.get(j);if(!z)throw Error(`Workflow state not found for ${j}`);let A=B(q(B(z)));return this.items.set(j,A),B(A)}async list(j){let q=[...this.items.values()];return((j?.status)?q.filter((A)=>A.status===j.status):q).map(B)}clear(){this.items.clear()}}function D(j){if(j instanceof Date)return new Date(j.getTime());if(Array.isArray(j))return j.map((q)=>D(q));if(j&&typeof j==="object"){let q={};for(let[z,A]of Object.entries(j))q[z]=D(A);return q}return j}export{O as InMemoryStateStore};
