@mastra/cloudflare-d1 1.0.0-beta.3 → 1.0.0-beta.5

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
@@ -1411,13 +1411,19 @@ var ScoresStorageD1 = class extends ScoresStorage {
1411
1411
  id: createStorageErrorId("CLOUDFLARE_D1", "SAVE_SCORE", "VALIDATION_FAILED"),
1412
1412
  domain: ErrorDomain.STORAGE,
1413
1413
  category: ErrorCategory.USER,
1414
- details: { scoreId: score.id }
1414
+ details: {
1415
+ scorer: score.scorer?.id ?? "unknown",
1416
+ entityId: score.entityId ?? "unknown",
1417
+ entityType: score.entityType ?? "unknown",
1418
+ traceId: score.traceId ?? "",
1419
+ spanId: score.spanId ?? ""
1420
+ }
1415
1421
  },
1416
1422
  error
1417
1423
  );
1418
1424
  }
1425
+ const id = crypto.randomUUID();
1419
1426
  try {
1420
- const id = crypto.randomUUID();
1421
1427
  const fullTableName = this.operations.getTableName(TABLE_SCORERS);
1422
1428
  const serializedRecord = {};
1423
1429
  for (const [key, value] of Object.entries(parsedScore)) {
@@ -1431,22 +1437,23 @@ var ScoresStorageD1 = class extends ScoresStorage {
1431
1437
  serializedRecord[key] = null;
1432
1438
  }
1433
1439
  }
1440
+ const now = /* @__PURE__ */ new Date();
1434
1441
  serializedRecord.id = id;
1435
- serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
1436
- serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
1442
+ serializedRecord.createdAt = now.toISOString();
1443
+ serializedRecord.updatedAt = now.toISOString();
1437
1444
  const columns = Object.keys(serializedRecord);
1438
1445
  const values = Object.values(serializedRecord);
1439
1446
  const query = createSqlBuilder().insert(fullTableName, columns, values);
1440
1447
  const { sql, params } = query.build();
1441
1448
  await this.operations.executeQuery({ sql, params });
1442
- const scoreFromDb = await this.getScoreById({ id });
1443
- return { score: scoreFromDb };
1449
+ return { score: { ...parsedScore, id, createdAt: now, updatedAt: now } };
1444
1450
  } catch (error) {
1445
1451
  throw new MastraError(
1446
1452
  {
1447
1453
  id: createStorageErrorId("CLOUDFLARE_D1", "SAVE_SCORE", "FAILED"),
1448
1454
  domain: ErrorDomain.STORAGE,
1449
- category: ErrorCategory.THIRD_PARTY
1455
+ category: ErrorCategory.THIRD_PARTY,
1456
+ details: { id }
1450
1457
  },
1451
1458
  error
1452
1459
  );
@@ -1893,6 +1900,25 @@ var WorkflowsStorageD1 = class extends WorkflowsStorage {
1893
1900
  );
1894
1901
  }
1895
1902
  }
1903
+ async deleteWorkflowRunById({ runId, workflowName }) {
1904
+ const fullTableName = this.operations.getTableName(TABLE_WORKFLOW_SNAPSHOT);
1905
+ try {
1906
+ const sql = `DELETE FROM ${fullTableName} WHERE workflow_name = ? AND run_id = ?`;
1907
+ const params = [workflowName, runId];
1908
+ await this.operations.executeQuery({ sql, params });
1909
+ } catch (error) {
1910
+ throw new MastraError(
1911
+ {
1912
+ id: createStorageErrorId("CLOUDFLARE_D1", "DELETE_WORKFLOW_RUN_BY_ID", "FAILED"),
1913
+ domain: ErrorDomain.STORAGE,
1914
+ category: ErrorCategory.THIRD_PARTY,
1915
+ text: `Failed to delete workflow run by ID: ${error instanceof Error ? error.message : String(error)}`,
1916
+ details: { runId, workflowName }
1917
+ },
1918
+ error
1919
+ );
1920
+ }
1921
+ }
1896
1922
  };
1897
1923
 
1898
1924
  // src/storage/index.ts
@@ -2074,6 +2100,9 @@ var D1Store = class extends MastraStorage {
2074
2100
  }) {
2075
2101
  return this.stores.workflows.getWorkflowRunById({ runId, workflowName });
2076
2102
  }
2103
+ async deleteWorkflowRunById({ runId, workflowName }) {
2104
+ return this.stores.workflows.deleteWorkflowRunById({ runId, workflowName });
2105
+ }
2077
2106
  /**
2078
2107
  * Insert multiple records in a batch operation
2079
2108
  * @param tableName The table to insert into
@@ -2101,8 +2130,8 @@ var D1Store = class extends MastraStorage {
2101
2130
  async getScoreById({ id: _id }) {
2102
2131
  return this.stores.scores.getScoreById({ id: _id });
2103
2132
  }
2104
- async saveScore(_score) {
2105
- return this.stores.scores.saveScore(_score);
2133
+ async saveScore(score) {
2134
+ return this.stores.scores.saveScore(score);
2106
2135
  }
2107
2136
  async listScoresByRunId({
2108
2137
  runId: _runId,