@mastra/cloudflare-d1 1.1.0-alpha.0 → 1.1.1-alpha.0
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/CHANGELOG.md +48 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-cloudflare-d1.md +2 -0
- package/dist/index.cjs +36 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -8
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +9 -5
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# @mastra/cloudflare-d1
|
|
2
2
|
|
|
3
|
+
## 1.1.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add optional `batchId`, `datasetId`, and `datasetItemId` fields to persisted scores so saved baseline scores can be grouped as one scoring pass and joined back to the dataset items they came from. ([#18331](https://github.com/mastra-ai/mastra/pull/18331))
|
|
8
|
+
- `scoreTrace()` accepts top-level `batchId`, `datasetId`, and `datasetItemId` when persisting a score for a stored trace.
|
|
9
|
+
- `ScoreRowData` and score save payloads now include nullable `batchId`, `datasetId`, and `datasetItemId`.
|
|
10
|
+
- Built-in stores with explicit score schema or attribute mappings now persist these provenance fields on saved scores.
|
|
11
|
+
- D1, DSQL, MSSQL, and Upstash score stores now apply additive provenance migrations or deterministic score ordering for persisted score reads.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
await scoreTrace({
|
|
15
|
+
storage,
|
|
16
|
+
scorer,
|
|
17
|
+
target: { traceId },
|
|
18
|
+
batchId: 'baseline-batch-1',
|
|
19
|
+
datasetId,
|
|
20
|
+
datasetItemId,
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- Added optional `organizationId` and `projectId` fields to scores for multi-tenant isolation. Scores can now be saved with tenancy metadata and the `listScoresBy*` methods accept a `filters` option to scope results by organization and project. ([#18331](https://github.com/mastra-ai/mastra/pull/18331))
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
await storage.saveScore({ ...score, organizationId: 'org-a', projectId: 'proj-1' });
|
|
28
|
+
|
|
29
|
+
const result = await storage.listScoresByScorerId({
|
|
30
|
+
scorerId,
|
|
31
|
+
filters: { organizationId: 'org-a', projectId: 'proj-1' },
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`projectId` identifies the project scope, separate from `resourceId` which continues to mean the agent memory resource.
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [[`9250acd`](https://github.com/mastra-ai/mastra/commit/9250acd1357f0f1f33d0dcca16f9655084c58eca), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`c64c2a8`](https://github.com/mastra-ai/mastra/commit/c64c2a8503a50252f9ca6b8e8c54cadee31b92a2), [`06e2680`](https://github.com/mastra-ai/mastra/commit/06e26806b51d2cbd858afdc66daa2b86ff3ba64a), [`1240f05`](https://github.com/mastra-ai/mastra/commit/1240f051c8e5371f1c014448bf37b1a1b9a05e47), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748)]:
|
|
38
|
+
- @mastra/core@1.49.0-alpha.5
|
|
39
|
+
|
|
40
|
+
## 1.1.0
|
|
41
|
+
|
|
42
|
+
### Minor Changes
|
|
43
|
+
|
|
44
|
+
- Random bump ([#18178](https://github.com/mastra-ai/mastra/pull/18178))
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies [[`7c0d868`](https://github.com/mastra-ai/mastra/commit/7c0d868d97d0fdbc04c14d0166dbf44d4c5a4a62), [`d9d2273`](https://github.com/mastra-ai/mastra/commit/d9d2273c702690c9a26eab2aebea879701d4355a), [`b04369d`](https://github.com/mastra-ai/mastra/commit/b04369d6b167c698ef103981171a8bf92808e756), [`8f3c262`](https://github.com/mastra-ai/mastra/commit/8f3c262587b335588a02d96b17fd6aca34c885b3)]:
|
|
49
|
+
- @mastra/core@1.45.0
|
|
50
|
+
|
|
3
51
|
## 1.1.0-alpha.0
|
|
4
52
|
|
|
5
53
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-cloudflare-d1
|
|
|
3
3
|
description: Documentation for @mastra/cloudflare-d1. Use when working with @mastra/cloudflare-d1 APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/cloudflare-d1"
|
|
6
|
-
version: "1.1.
|
|
6
|
+
version: "1.1.1-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
1
3
|
# Cloudflare D1 storage
|
|
2
4
|
|
|
3
5
|
The Cloudflare D1 storage implementation provides a serverless SQL database solution using Cloudflare D1, supporting relational operations and transactional consistency.
|
package/dist/index.cjs
CHANGED
|
@@ -1871,6 +1871,14 @@ var MemoryStorageD1 = class extends storage.MemoryStorage {
|
|
|
1871
1871
|
}
|
|
1872
1872
|
}
|
|
1873
1873
|
};
|
|
1874
|
+
function applyTenancyFilters(query, filters) {
|
|
1875
|
+
if (filters?.organizationId !== void 0) {
|
|
1876
|
+
query.andWhere("organizationId = ?", filters.organizationId);
|
|
1877
|
+
}
|
|
1878
|
+
if (filters?.projectId !== void 0) {
|
|
1879
|
+
query.andWhere("projectId = ?", filters.projectId);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1874
1882
|
function transformScoreRow(row) {
|
|
1875
1883
|
return storage.transformScoreRow(row, {
|
|
1876
1884
|
preferredTimestampFields: {
|
|
@@ -1887,6 +1895,11 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1887
1895
|
}
|
|
1888
1896
|
async init() {
|
|
1889
1897
|
await this.#db.createTable({ tableName: storage.TABLE_SCORERS, schema: storage.TABLE_SCHEMAS[storage.TABLE_SCORERS] });
|
|
1898
|
+
await this.#db.alterTable({
|
|
1899
|
+
tableName: storage.TABLE_SCORERS,
|
|
1900
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_SCORERS],
|
|
1901
|
+
ifNotExists: ["organizationId", "projectId", "batchId", "datasetId", "datasetItemId"]
|
|
1902
|
+
});
|
|
1890
1903
|
}
|
|
1891
1904
|
async dangerouslyClearAll() {
|
|
1892
1905
|
await this.#db.clearTable({ tableName: storage.TABLE_SCORERS });
|
|
@@ -1975,7 +1988,8 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1975
1988
|
entityId,
|
|
1976
1989
|
entityType,
|
|
1977
1990
|
source,
|
|
1978
|
-
pagination
|
|
1991
|
+
pagination,
|
|
1992
|
+
filters
|
|
1979
1993
|
}) {
|
|
1980
1994
|
try {
|
|
1981
1995
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -1992,6 +2006,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
1992
2006
|
if (source) {
|
|
1993
2007
|
countQuery.andWhere("source = ?", source);
|
|
1994
2008
|
}
|
|
2009
|
+
applyTenancyFilters(countQuery, filters);
|
|
1995
2010
|
const countResult = await this.#db.executeQuery(countQuery.build());
|
|
1996
2011
|
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
1997
2012
|
if (total === 0) {
|
|
@@ -2017,7 +2032,8 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2017
2032
|
if (source) {
|
|
2018
2033
|
selectQuery.andWhere("source = ?", source);
|
|
2019
2034
|
}
|
|
2020
|
-
selectQuery
|
|
2035
|
+
applyTenancyFilters(selectQuery, filters);
|
|
2036
|
+
selectQuery.orderBy("createdAt", "DESC").limit(limitValue).offset(start);
|
|
2021
2037
|
const { sql, params } = selectQuery.build();
|
|
2022
2038
|
const results = await this.#db.executeQuery({ sql, params });
|
|
2023
2039
|
const scores = Array.isArray(results) ? results.map(transformScoreRow) : [];
|
|
@@ -2043,7 +2059,8 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2043
2059
|
}
|
|
2044
2060
|
async listScoresByRunId({
|
|
2045
2061
|
runId,
|
|
2046
|
-
pagination
|
|
2062
|
+
pagination,
|
|
2063
|
+
filters
|
|
2047
2064
|
}) {
|
|
2048
2065
|
try {
|
|
2049
2066
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -2051,6 +2068,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2051
2068
|
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2052
2069
|
const fullTableName = this.#db.getTableName(storage.TABLE_SCORERS);
|
|
2053
2070
|
const countQuery = createSqlBuilder().count().from(fullTableName).where("runId = ?", runId);
|
|
2071
|
+
applyTenancyFilters(countQuery, filters);
|
|
2054
2072
|
const countResult = await this.#db.executeQuery(countQuery.build());
|
|
2055
2073
|
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
2056
2074
|
if (total === 0) {
|
|
@@ -2066,7 +2084,9 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2066
2084
|
}
|
|
2067
2085
|
const end = perPageInput === false ? total : start + perPage;
|
|
2068
2086
|
const limitValue = perPageInput === false ? total : perPage;
|
|
2069
|
-
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("runId = ?", runId)
|
|
2087
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("runId = ?", runId);
|
|
2088
|
+
applyTenancyFilters(selectQuery, filters);
|
|
2089
|
+
selectQuery.orderBy("createdAt", "DESC").limit(limitValue).offset(start);
|
|
2070
2090
|
const { sql, params } = selectQuery.build();
|
|
2071
2091
|
const results = await this.#db.executeQuery({ sql, params });
|
|
2072
2092
|
const scores = Array.isArray(results) ? results.map(transformScoreRow) : [];
|
|
@@ -2093,7 +2113,8 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2093
2113
|
async listScoresByEntityId({
|
|
2094
2114
|
entityId,
|
|
2095
2115
|
entityType,
|
|
2096
|
-
pagination
|
|
2116
|
+
pagination,
|
|
2117
|
+
filters
|
|
2097
2118
|
}) {
|
|
2098
2119
|
try {
|
|
2099
2120
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -2101,6 +2122,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2101
2122
|
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2102
2123
|
const fullTableName = this.#db.getTableName(storage.TABLE_SCORERS);
|
|
2103
2124
|
const countQuery = createSqlBuilder().count().from(fullTableName).where("entityId = ?", entityId).andWhere("entityType = ?", entityType);
|
|
2125
|
+
applyTenancyFilters(countQuery, filters);
|
|
2104
2126
|
const countResult = await this.#db.executeQuery(countQuery.build());
|
|
2105
2127
|
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
2106
2128
|
if (total === 0) {
|
|
@@ -2116,7 +2138,9 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2116
2138
|
}
|
|
2117
2139
|
const end = perPageInput === false ? total : start + perPage;
|
|
2118
2140
|
const limitValue = perPageInput === false ? total : perPage;
|
|
2119
|
-
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("entityId = ?", entityId).andWhere("entityType = ?", entityType)
|
|
2141
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("entityId = ?", entityId).andWhere("entityType = ?", entityType);
|
|
2142
|
+
applyTenancyFilters(selectQuery, filters);
|
|
2143
|
+
selectQuery.orderBy("createdAt", "DESC").limit(limitValue).offset(start);
|
|
2120
2144
|
const { sql, params } = selectQuery.build();
|
|
2121
2145
|
const results = await this.#db.executeQuery({ sql, params });
|
|
2122
2146
|
const scores = Array.isArray(results) ? results.map(transformScoreRow) : [];
|
|
@@ -2143,7 +2167,8 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2143
2167
|
async listScoresBySpan({
|
|
2144
2168
|
traceId,
|
|
2145
2169
|
spanId,
|
|
2146
|
-
pagination
|
|
2170
|
+
pagination,
|
|
2171
|
+
filters
|
|
2147
2172
|
}) {
|
|
2148
2173
|
try {
|
|
2149
2174
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -2151,6 +2176,7 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2151
2176
|
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2152
2177
|
const fullTableName = this.#db.getTableName(storage.TABLE_SCORERS);
|
|
2153
2178
|
const countQuery = createSqlBuilder().count().from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId);
|
|
2179
|
+
applyTenancyFilters(countQuery, filters);
|
|
2154
2180
|
const countResult = await this.#db.executeQuery(countQuery.build());
|
|
2155
2181
|
const total = Array.isArray(countResult) ? Number(countResult?.[0]?.count ?? 0) : Number(countResult?.count ?? 0);
|
|
2156
2182
|
if (total === 0) {
|
|
@@ -2166,7 +2192,9 @@ var ScoresStorageD1 = class extends storage.ScoresStorage {
|
|
|
2166
2192
|
}
|
|
2167
2193
|
const end = perPageInput === false ? total : start + perPage;
|
|
2168
2194
|
const limitValue = perPageInput === false ? total : perPage;
|
|
2169
|
-
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId)
|
|
2195
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("traceId = ?", traceId).andWhere("spanId = ?", spanId);
|
|
2196
|
+
applyTenancyFilters(selectQuery, filters);
|
|
2197
|
+
selectQuery.orderBy("createdAt", "DESC").limit(limitValue).offset(start);
|
|
2170
2198
|
const { sql, params } = selectQuery.build();
|
|
2171
2199
|
const results = await this.#db.executeQuery({ sql, params });
|
|
2172
2200
|
const scores = Array.isArray(results) ? results.map(transformScoreRow) : [];
|