@mastra/cloudflare-d1 0.12.5 → 0.12.6
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.cjs +46 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -20
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +5 -2
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +5 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1443,6 +1443,7 @@ var StoreOperationsD1 = class extends storage.StoreOperations {
|
|
|
1443
1443
|
query.andWhere(`${key} = ?`, value);
|
|
1444
1444
|
}
|
|
1445
1445
|
}
|
|
1446
|
+
query.orderBy("createdAt", "DESC");
|
|
1446
1447
|
query.limit(1);
|
|
1447
1448
|
const { sql, params } = query.build();
|
|
1448
1449
|
const result = await this.executeQuery({ sql, params, first: true });
|
|
@@ -1527,20 +1528,19 @@ var StoreOperationsD1 = class extends storage.StoreOperations {
|
|
|
1527
1528
|
}
|
|
1528
1529
|
};
|
|
1529
1530
|
function transformScoreRow(row) {
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
};
|
|
1531
|
+
const deserialized = { ...row };
|
|
1532
|
+
deserialized.input = storage.safelyParseJSON(row.input);
|
|
1533
|
+
deserialized.output = storage.safelyParseJSON(row.output);
|
|
1534
|
+
deserialized.scorer = storage.safelyParseJSON(row.scorer);
|
|
1535
|
+
deserialized.preprocessStepResult = storage.safelyParseJSON(row.preprocessStepResult);
|
|
1536
|
+
deserialized.analyzeStepResult = storage.safelyParseJSON(row.analyzeStepResult);
|
|
1537
|
+
deserialized.metadata = storage.safelyParseJSON(row.metadata);
|
|
1538
|
+
deserialized.additionalContext = storage.safelyParseJSON(row.additionalContext);
|
|
1539
|
+
deserialized.runtimeContext = storage.safelyParseJSON(row.runtimeContext);
|
|
1540
|
+
deserialized.entity = storage.safelyParseJSON(row.entity);
|
|
1541
|
+
deserialized.createdAt = row.createdAtZ || row.createdAt;
|
|
1542
|
+
deserialized.updatedAt = row.updatedAtZ || row.updatedAt;
|
|
1543
|
+
return deserialized;
|
|
1544
1544
|
}
|
|
1545
1545
|
var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
1546
1546
|
operations;
|
|
@@ -1571,6 +1571,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1571
1571
|
}
|
|
1572
1572
|
async saveScore(score) {
|
|
1573
1573
|
try {
|
|
1574
|
+
const id = crypto.randomUUID();
|
|
1574
1575
|
const fullTableName = this.operations.getTableName(storage.TABLE_SCORERS);
|
|
1575
1576
|
const { input, ...rest } = score;
|
|
1576
1577
|
const serializedRecord = {};
|
|
@@ -1585,6 +1586,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1585
1586
|
serializedRecord[key] = null;
|
|
1586
1587
|
}
|
|
1587
1588
|
}
|
|
1589
|
+
serializedRecord.id = id;
|
|
1588
1590
|
serializedRecord.input = JSON.stringify(input);
|
|
1589
1591
|
serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1590
1592
|
serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -1593,7 +1595,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1593
1595
|
const query = createSqlBuilder().insert(fullTableName, columns, values);
|
|
1594
1596
|
const { sql, params } = query.build();
|
|
1595
1597
|
await this.operations.executeQuery({ sql, params });
|
|
1596
|
-
const scoreFromDb = await this.getScoreById({ id
|
|
1598
|
+
const scoreFromDb = await this.getScoreById({ id });
|
|
1597
1599
|
return { score: scoreFromDb };
|
|
1598
1600
|
} catch (error$1) {
|
|
1599
1601
|
throw new error.MastraError(
|
|
@@ -1608,11 +1610,23 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1608
1610
|
}
|
|
1609
1611
|
async getScoresByScorerId({
|
|
1610
1612
|
scorerId,
|
|
1613
|
+
entityId,
|
|
1614
|
+
entityType,
|
|
1615
|
+
source,
|
|
1611
1616
|
pagination
|
|
1612
1617
|
}) {
|
|
1613
1618
|
try {
|
|
1614
1619
|
const fullTableName = this.operations.getTableName(storage.TABLE_SCORERS);
|
|
1615
1620
|
const countQuery = createSqlBuilder().count().from(fullTableName).where("scorerId = ?", scorerId);
|
|
1621
|
+
if (entityId) {
|
|
1622
|
+
countQuery.andWhere("entityId = ?", entityId);
|
|
1623
|
+
}
|
|
1624
|
+
if (entityType) {
|
|
1625
|
+
countQuery.andWhere("entityType = ?", entityType);
|
|
1626
|
+
}
|
|
1627
|
+
if (source) {
|
|
1628
|
+
countQuery.andWhere("source = ?", source);
|
|
1629
|
+
}
|
|
1616
1630
|
const countResult = await this.operations.executeQuery(countQuery.build());
|
|
1617
1631
|
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
1618
1632
|
if (total === 0) {
|
|
@@ -1626,7 +1640,17 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1626
1640
|
scores: []
|
|
1627
1641
|
};
|
|
1628
1642
|
}
|
|
1629
|
-
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("scorerId = ?", scorerId)
|
|
1643
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("scorerId = ?", scorerId);
|
|
1644
|
+
if (entityId) {
|
|
1645
|
+
selectQuery.andWhere("entityId = ?", entityId);
|
|
1646
|
+
}
|
|
1647
|
+
if (entityType) {
|
|
1648
|
+
selectQuery.andWhere("entityType = ?", entityType);
|
|
1649
|
+
}
|
|
1650
|
+
if (source) {
|
|
1651
|
+
selectQuery.andWhere("source = ?", source);
|
|
1652
|
+
}
|
|
1653
|
+
selectQuery.limit(pagination.perPage).offset(pagination.page * pagination.perPage);
|
|
1630
1654
|
const { sql, params } = selectQuery.build();
|
|
1631
1655
|
const results = await this.operations.executeQuery({ sql, params });
|
|
1632
1656
|
const scores = Array.isArray(results) ? results.map(transformScoreRow) : [];
|
|
@@ -2322,10 +2346,13 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
2322
2346
|
});
|
|
2323
2347
|
}
|
|
2324
2348
|
async getScoresByScorerId({
|
|
2325
|
-
scorerId
|
|
2326
|
-
pagination
|
|
2349
|
+
scorerId,
|
|
2350
|
+
pagination,
|
|
2351
|
+
entityId,
|
|
2352
|
+
entityType,
|
|
2353
|
+
source
|
|
2327
2354
|
}) {
|
|
2328
|
-
return this.stores.scores.getScoresByScorerId({ scorerId
|
|
2355
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
2329
2356
|
}
|
|
2330
2357
|
/**
|
|
2331
2358
|
* Close the database connection
|