@mastra/cloudflare-d1 0.0.0-zod-v4-compat-part-2-20250822105954 → 0.0.0-zod-v4-stuff-20250825154219
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 +93 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +94 -20
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/legacy-evals/index.d.ts +1 -1
- package/dist/storage/domains/memory/index.d.ts +9 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +6 -3
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -1
- package/dist/storage/index.d.ts +13 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +9 -8
package/dist/index.cjs
CHANGED
|
@@ -926,6 +926,47 @@ var MemoryStorageD1 = class extends storage.MemoryStorage {
|
|
|
926
926
|
throw mastraError;
|
|
927
927
|
}
|
|
928
928
|
}
|
|
929
|
+
async getMessagesById({
|
|
930
|
+
messageIds,
|
|
931
|
+
format
|
|
932
|
+
}) {
|
|
933
|
+
if (messageIds.length === 0) return [];
|
|
934
|
+
const fullTableName = this.operations.getTableName(storage.TABLE_MESSAGES);
|
|
935
|
+
const messages = [];
|
|
936
|
+
try {
|
|
937
|
+
const query = createSqlBuilder().select(["id", "content", "role", "type", "createdAt", "thread_id AS threadId", "resourceId"]).from(fullTableName).where(`id in (${messageIds.map(() => "?").join(",")})`, ...messageIds);
|
|
938
|
+
query.orderBy("createdAt", "DESC");
|
|
939
|
+
const { sql, params } = query.build();
|
|
940
|
+
const result = await this.operations.executeQuery({ sql, params });
|
|
941
|
+
if (Array.isArray(result)) messages.push(...result);
|
|
942
|
+
const processedMessages = messages.map((message) => {
|
|
943
|
+
const processedMsg = {};
|
|
944
|
+
for (const [key, value] of Object.entries(message)) {
|
|
945
|
+
if (key === `type` && value === `v2`) continue;
|
|
946
|
+
processedMsg[key] = deserializeValue(value);
|
|
947
|
+
}
|
|
948
|
+
return processedMsg;
|
|
949
|
+
});
|
|
950
|
+
this.logger.debug(`Retrieved ${messages.length} messages`);
|
|
951
|
+
const list = new agent.MessageList().add(processedMessages, "memory");
|
|
952
|
+
if (format === `v1`) return list.get.all.v1();
|
|
953
|
+
return list.get.all.v2();
|
|
954
|
+
} catch (error$1) {
|
|
955
|
+
const mastraError = new error.MastraError(
|
|
956
|
+
{
|
|
957
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_MESSAGES_BY_ID_ERROR",
|
|
958
|
+
domain: error.ErrorDomain.STORAGE,
|
|
959
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
960
|
+
text: `Failed to retrieve messages by ID: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
961
|
+
details: { messageIds: JSON.stringify(messageIds) }
|
|
962
|
+
},
|
|
963
|
+
error$1
|
|
964
|
+
);
|
|
965
|
+
this.logger?.error(mastraError.toString());
|
|
966
|
+
this.logger?.trackException(mastraError);
|
|
967
|
+
throw mastraError;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
929
970
|
async getMessagesPaginated({
|
|
930
971
|
threadId,
|
|
931
972
|
selectBy,
|
|
@@ -1443,6 +1484,7 @@ var StoreOperationsD1 = class extends storage.StoreOperations {
|
|
|
1443
1484
|
query.andWhere(`${key} = ?`, value);
|
|
1444
1485
|
}
|
|
1445
1486
|
}
|
|
1487
|
+
query.orderBy("createdAt", "DESC");
|
|
1446
1488
|
query.limit(1);
|
|
1447
1489
|
const { sql, params } = query.build();
|
|
1448
1490
|
const result = await this.executeQuery({ sql, params, first: true });
|
|
@@ -1527,20 +1569,19 @@ var StoreOperationsD1 = class extends storage.StoreOperations {
|
|
|
1527
1569
|
}
|
|
1528
1570
|
};
|
|
1529
1571
|
function transformScoreRow(row) {
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
};
|
|
1572
|
+
const deserialized = { ...row };
|
|
1573
|
+
deserialized.input = storage.safelyParseJSON(row.input);
|
|
1574
|
+
deserialized.output = storage.safelyParseJSON(row.output);
|
|
1575
|
+
deserialized.scorer = storage.safelyParseJSON(row.scorer);
|
|
1576
|
+
deserialized.preprocessStepResult = storage.safelyParseJSON(row.preprocessStepResult);
|
|
1577
|
+
deserialized.analyzeStepResult = storage.safelyParseJSON(row.analyzeStepResult);
|
|
1578
|
+
deserialized.metadata = storage.safelyParseJSON(row.metadata);
|
|
1579
|
+
deserialized.additionalContext = storage.safelyParseJSON(row.additionalContext);
|
|
1580
|
+
deserialized.runtimeContext = storage.safelyParseJSON(row.runtimeContext);
|
|
1581
|
+
deserialized.entity = storage.safelyParseJSON(row.entity);
|
|
1582
|
+
deserialized.createdAt = row.createdAtZ || row.createdAt;
|
|
1583
|
+
deserialized.updatedAt = row.updatedAtZ || row.updatedAt;
|
|
1584
|
+
return deserialized;
|
|
1544
1585
|
}
|
|
1545
1586
|
var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
1546
1587
|
operations;
|
|
@@ -1571,6 +1612,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1571
1612
|
}
|
|
1572
1613
|
async saveScore(score) {
|
|
1573
1614
|
try {
|
|
1615
|
+
const id = crypto.randomUUID();
|
|
1574
1616
|
const fullTableName = this.operations.getTableName(storage.TABLE_SCORERS);
|
|
1575
1617
|
const { input, ...rest } = score;
|
|
1576
1618
|
const serializedRecord = {};
|
|
@@ -1585,6 +1627,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1585
1627
|
serializedRecord[key] = null;
|
|
1586
1628
|
}
|
|
1587
1629
|
}
|
|
1630
|
+
serializedRecord.id = id;
|
|
1588
1631
|
serializedRecord.input = JSON.stringify(input);
|
|
1589
1632
|
serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1590
1633
|
serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -1593,7 +1636,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1593
1636
|
const query = createSqlBuilder().insert(fullTableName, columns, values);
|
|
1594
1637
|
const { sql, params } = query.build();
|
|
1595
1638
|
await this.operations.executeQuery({ sql, params });
|
|
1596
|
-
const scoreFromDb = await this.getScoreById({ id
|
|
1639
|
+
const scoreFromDb = await this.getScoreById({ id });
|
|
1597
1640
|
return { score: scoreFromDb };
|
|
1598
1641
|
} catch (error$1) {
|
|
1599
1642
|
throw new error.MastraError(
|
|
@@ -1608,11 +1651,23 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1608
1651
|
}
|
|
1609
1652
|
async getScoresByScorerId({
|
|
1610
1653
|
scorerId,
|
|
1654
|
+
entityId,
|
|
1655
|
+
entityType,
|
|
1656
|
+
source,
|
|
1611
1657
|
pagination
|
|
1612
1658
|
}) {
|
|
1613
1659
|
try {
|
|
1614
1660
|
const fullTableName = this.operations.getTableName(storage.TABLE_SCORERS);
|
|
1615
1661
|
const countQuery = createSqlBuilder().count().from(fullTableName).where("scorerId = ?", scorerId);
|
|
1662
|
+
if (entityId) {
|
|
1663
|
+
countQuery.andWhere("entityId = ?", entityId);
|
|
1664
|
+
}
|
|
1665
|
+
if (entityType) {
|
|
1666
|
+
countQuery.andWhere("entityType = ?", entityType);
|
|
1667
|
+
}
|
|
1668
|
+
if (source) {
|
|
1669
|
+
countQuery.andWhere("source = ?", source);
|
|
1670
|
+
}
|
|
1616
1671
|
const countResult = await this.operations.executeQuery(countQuery.build());
|
|
1617
1672
|
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
1618
1673
|
if (total === 0) {
|
|
@@ -1626,7 +1681,17 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1626
1681
|
scores: []
|
|
1627
1682
|
};
|
|
1628
1683
|
}
|
|
1629
|
-
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("scorerId = ?", scorerId)
|
|
1684
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("scorerId = ?", scorerId);
|
|
1685
|
+
if (entityId) {
|
|
1686
|
+
selectQuery.andWhere("entityId = ?", entityId);
|
|
1687
|
+
}
|
|
1688
|
+
if (entityType) {
|
|
1689
|
+
selectQuery.andWhere("entityType = ?", entityType);
|
|
1690
|
+
}
|
|
1691
|
+
if (source) {
|
|
1692
|
+
selectQuery.andWhere("source = ?", source);
|
|
1693
|
+
}
|
|
1694
|
+
selectQuery.limit(pagination.perPage).offset(pagination.page * pagination.perPage);
|
|
1630
1695
|
const { sql, params } = selectQuery.build();
|
|
1631
1696
|
const results = await this.operations.executeQuery({ sql, params });
|
|
1632
1697
|
const scores = Array.isArray(results) ? results.map(transformScoreRow) : [];
|
|
@@ -2223,6 +2288,12 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
2223
2288
|
}) {
|
|
2224
2289
|
return this.stores.memory.getMessages({ threadId, selectBy, format });
|
|
2225
2290
|
}
|
|
2291
|
+
async getMessagesById({
|
|
2292
|
+
messageIds,
|
|
2293
|
+
format
|
|
2294
|
+
}) {
|
|
2295
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2296
|
+
}
|
|
2226
2297
|
async getMessagesPaginated({
|
|
2227
2298
|
threadId,
|
|
2228
2299
|
selectBy,
|
|
@@ -2322,10 +2393,13 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
2322
2393
|
});
|
|
2323
2394
|
}
|
|
2324
2395
|
async getScoresByScorerId({
|
|
2325
|
-
scorerId
|
|
2326
|
-
pagination
|
|
2396
|
+
scorerId,
|
|
2397
|
+
pagination,
|
|
2398
|
+
entityId,
|
|
2399
|
+
entityType,
|
|
2400
|
+
source
|
|
2327
2401
|
}) {
|
|
2328
|
-
return this.stores.scores.getScoresByScorerId({ scorerId
|
|
2402
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
2329
2403
|
}
|
|
2330
2404
|
/**
|
|
2331
2405
|
* Close the database connection
|