var{defineProperty:K,getOwnPropertyNames:M,getOwnPropertyDescriptor:Q}=Object,R=Object.prototype.hasOwnProperty;function T(j){return this[j]}var Y=(j)=>{var q=(L??=new WeakMap).get(j),D;if(q)return q;if(q=K({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var B of M(j))if(!R.call(q,B))K(q,B,{get:T.bind(j,B),enumerable:!(D=Q(j,B))||D.enumerable})}return L.set(j,q),q},L;var U=(j)=>j;function V(j,q){this[j]=U.bind(null,q)}var Z=(j,q)=>{for(var D in q)K(j,D,{get:q[D],enumerable:!0,configurable:!0,set:V.bind(q,D)})};var _=(j,q)=>()=>(j&&(q=j(j=0)),q);class W{prisma;constructor(j){this.prisma=j}async create(j){await this.prisma.workflowState.create({data:{id:j.workflowId,name:j.workflowName,version:j.workflowVersion,status:j.status,currentStep:j.currentStep,data:j.data,history:j.history,retryCounts:j.retryCounts??{},createdAt:j.createdAt,updatedAt:j.updatedAt}})}async get(j){let q=await this.prisma.workflowState.findUnique({where:{id:j}});if(!q)return;return{workflowId:q.id,workflowName:q.name,workflowVersion:q.version,currentStep:q.currentStep,data:q.data,history:q.history,retryCounts:q.retryCounts,status:q.status,createdAt:q.createdAt,updatedAt:q.updatedAt}}async update(j,q){let D=await this.get(j);if(!D)throw Error(`Workflow ${j} not found`);let B=q(D),E=await this.prisma.workflowState.update({where:{id:j},data:{status:B.status,currentStep:B.currentStep,data:B.data,history:B.history,retryCounts:B.retryCounts,updatedAt:B.updatedAt}});return{workflowId:E.id,workflowName:E.name,workflowVersion:E.version,currentStep:E.currentStep,data:E.data,history:E.history,retryCounts:E.retryCounts,status:E.status,createdAt:E.createdAt,updatedAt:E.updatedAt}}async list(j){let q={};if(j?.status)q.status=j.status;return(await this.prisma.workflowState.findMany({where:q})).map((B)=>({workflowId:B.id,workflowName:B.name,workflowVersion:B.version,currentStep:B.currentStep,data:B.data,history:B.history,retryCounts:B.retryCounts,status:B.status,createdAt:B.createdAt,updatedAt:B.updatedAt}))}}function G(j){throw Error("File-backed state store adapter not implemented. Provide a custom adapter that satisfies StateStore.")}function F(j){return{...j,data:H(j.data),history:j.history.map((q)=>({...q,input:H(q.input),output:H(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 X{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,F(j))}async get(j){let q=this.items.get(j);return q?F(q):void 0}async update(j,q){let D=this.items.get(j);if(!D)throw Error(`Workflow state not found for ${j}`);let B=F(q(F(D)));return this.items.set(j,B),F(B)}async list(j){let q=[...this.items.values()];return((j?.status)?q.filter((B)=>B.status===j.status):q).map(F)}clear(){this.items.clear()}}function H(j){if(j instanceof Date)return new Date(j.getTime());if(Array.isArray(j))return j.map((q)=>H(q));if(j&&typeof j==="object"){let q={};for(let[D,B]of Object.entries(j))q[D]=H(B);return q}return j}export{G as createFileStateStore,W as PrismaStateStore,X as InMemoryStateStore};
