@mastra/dynamodb 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2780,17 +2780,35 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2780
2780
  this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
2781
2781
  try {
2782
2782
  const now = /* @__PURE__ */ new Date();
2783
+ const createdAtValue = (createdAt ?? now).toISOString();
2784
+ const updatedAtValue = (updatedAt ?? now).toISOString();
2783
2785
  const data = {
2784
2786
  entity: "workflow_snapshot",
2785
2787
  workflow_name: workflowName,
2786
2788
  run_id: runId,
2787
2789
  snapshot: JSON.stringify(snapshot),
2788
- createdAt: (createdAt ?? now).toISOString(),
2789
- updatedAt: (updatedAt ?? now).toISOString(),
2790
+ createdAt: createdAtValue,
2791
+ updatedAt: updatedAtValue,
2790
2792
  resourceId,
2791
2793
  ...getTtlProps("workflow_snapshot", this.ttlConfig)
2792
2794
  };
2793
- await this.service.entities.workflow_snapshot.upsert(data).go();
2795
+ try {
2796
+ await this.service.entities.workflow_snapshot.create(data).where((attr, op) => op.notExists(attr.run_id)).go();
2797
+ } catch (error) {
2798
+ if (!this.isConditionalCheckFailed(error)) {
2799
+ throw error;
2800
+ }
2801
+ await this.service.entities.workflow_snapshot.update({
2802
+ entity: "workflow_snapshot",
2803
+ workflow_name: workflowName,
2804
+ run_id: runId
2805
+ }).set({
2806
+ snapshot: JSON.stringify(snapshot),
2807
+ updatedAt: updatedAtValue,
2808
+ resourceId,
2809
+ ...getTtlProps("workflow_snapshot", this.ttlConfig)
2810
+ }).go();
2811
+ }
2794
2812
  } catch (error) {
2795
2813
  throw new MastraError(
2796
2814
  {