@mastra/mongodb 1.12.0-alpha.1 → 1.12.0-alpha.2
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 +118 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +102 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +102 -29
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts +6 -7
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts +9 -5
- package/dist/storage/domains/experiments/index.d.ts.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/dist/storage/domains/utils.d.ts +18 -0
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { skillSnapshotFieldValuesEqual } from '@mastra/core/storage/domains/skil
|
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
15
|
var package_default = {
|
|
16
|
-
version: "1.12.0-alpha.
|
|
16
|
+
version: "1.12.0-alpha.2"};
|
|
17
17
|
var MongoDBFilterTranslator = class extends BaseFilterTranslator {
|
|
18
18
|
getSupportedOperators() {
|
|
19
19
|
return {
|
|
@@ -2149,6 +2149,16 @@ var MongoDBBlobStore = class _MongoDBBlobStore extends BlobStore {
|
|
|
2149
2149
|
};
|
|
2150
2150
|
}
|
|
2151
2151
|
};
|
|
2152
|
+
function formatDateForMongoDB(date) {
|
|
2153
|
+
return typeof date === "string" ? new Date(date) : date;
|
|
2154
|
+
}
|
|
2155
|
+
function applyTenancyFilter(filter, filters) {
|
|
2156
|
+
if (!filters) return;
|
|
2157
|
+
if (filters.organizationId !== void 0) filter.organizationId = filters.organizationId;
|
|
2158
|
+
if (filters.projectId !== void 0) filter.projectId = filters.projectId;
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
// src/storage/domains/datasets/index.ts
|
|
2152
2162
|
var MANAGED_COLLECTIONS = [TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS];
|
|
2153
2163
|
var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
2154
2164
|
#connector;
|
|
@@ -2343,10 +2353,15 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
2343
2353
|
);
|
|
2344
2354
|
}
|
|
2345
2355
|
}
|
|
2346
|
-
async getDatasetById({
|
|
2356
|
+
async getDatasetById({
|
|
2357
|
+
id,
|
|
2358
|
+
filters
|
|
2359
|
+
}) {
|
|
2347
2360
|
try {
|
|
2348
2361
|
const collection = await this.getCollection(TABLE_DATASETS);
|
|
2349
|
-
const
|
|
2362
|
+
const query = { id };
|
|
2363
|
+
applyTenancyFilter(query, filters);
|
|
2364
|
+
const row = await collection.findOne(query);
|
|
2350
2365
|
return row ? this.transformDatasetRow(row) : null;
|
|
2351
2366
|
} catch (error) {
|
|
2352
2367
|
throw new MastraError(
|
|
@@ -2361,7 +2376,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
2361
2376
|
}
|
|
2362
2377
|
async _doUpdateDataset(args) {
|
|
2363
2378
|
try {
|
|
2364
|
-
const existing = await this.getDatasetById({ id: args.id });
|
|
2379
|
+
const existing = await this.getDatasetById({ id: args.id, filters: args.filters });
|
|
2365
2380
|
if (!existing) {
|
|
2366
2381
|
throw new MastraError({
|
|
2367
2382
|
id: createStorageErrorId("MONGODB", "UPDATE_DATASET", "NOT_FOUND"),
|
|
@@ -2398,8 +2413,13 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
2398
2413
|
);
|
|
2399
2414
|
}
|
|
2400
2415
|
}
|
|
2401
|
-
async deleteDataset({ id }) {
|
|
2416
|
+
async deleteDataset({ id, filters }) {
|
|
2402
2417
|
try {
|
|
2418
|
+
const datasetsCollectionForGate = await this.getCollection(TABLE_DATASETS);
|
|
2419
|
+
const gateQuery = { id };
|
|
2420
|
+
applyTenancyFilter(gateQuery, filters);
|
|
2421
|
+
const gateHit = await datasetsCollectionForGate.findOne(gateQuery, { projection: { id: 1 } });
|
|
2422
|
+
if (!gateHit) return;
|
|
2403
2423
|
try {
|
|
2404
2424
|
const experimentsCollection = await this.getCollection(TABLE_EXPERIMENTS);
|
|
2405
2425
|
const experimentIds = await experimentsCollection.find({ datasetId: id }, { projection: { id: 1 } }).toArray();
|
|
@@ -2419,7 +2439,9 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
2419
2439
|
const datasetsCollection = await this.getCollection(TABLE_DATASETS);
|
|
2420
2440
|
await versionsCollection.deleteMany({ datasetId: id });
|
|
2421
2441
|
await itemsCollection.deleteMany({ datasetId: id });
|
|
2422
|
-
|
|
2442
|
+
const parentDeleteQuery = { id };
|
|
2443
|
+
applyTenancyFilter(parentDeleteQuery, filters);
|
|
2444
|
+
await datasetsCollection.deleteOne(parentDeleteQuery);
|
|
2423
2445
|
} catch (error) {
|
|
2424
2446
|
if (error instanceof MastraError) throw error;
|
|
2425
2447
|
throw new MastraError(
|
|
@@ -2441,6 +2463,14 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
2441
2463
|
if (args.filters?.projectId !== void 0) filter.projectId = args.filters.projectId;
|
|
2442
2464
|
if (args.filters?.candidateKey !== void 0) filter.candidateKey = args.filters.candidateKey;
|
|
2443
2465
|
if (args.filters?.candidateId !== void 0) filter.candidateId = args.filters.candidateId;
|
|
2466
|
+
if (args.filters?.targetType !== void 0) filter.targetType = args.filters.targetType;
|
|
2467
|
+
if (args.filters?.targetIds !== void 0 && args.filters.targetIds.length > 0) {
|
|
2468
|
+
filter.targetIds = { $in: args.filters.targetIds };
|
|
2469
|
+
}
|
|
2470
|
+
if (args.filters?.name !== void 0 && args.filters.name.length > 0) {
|
|
2471
|
+
const escapedName = args.filters.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2472
|
+
filter.name = { $regex: escapedName, $options: "i" };
|
|
2473
|
+
}
|
|
2444
2474
|
const total = await collection.countDocuments(filter);
|
|
2445
2475
|
if (total === 0) {
|
|
2446
2476
|
return { datasets: [], pagination: { total: 0, page, perPage: perPageInput, hasMore: false } };
|
|
@@ -3441,10 +3471,15 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
|
|
|
3441
3471
|
);
|
|
3442
3472
|
}
|
|
3443
3473
|
}
|
|
3444
|
-
async getExperimentById({
|
|
3474
|
+
async getExperimentById({
|
|
3475
|
+
id,
|
|
3476
|
+
filters
|
|
3477
|
+
}) {
|
|
3445
3478
|
try {
|
|
3446
3479
|
const collection = await this.getCollection(TABLE_EXPERIMENTS);
|
|
3447
|
-
const
|
|
3480
|
+
const query = { id };
|
|
3481
|
+
applyTenancyFilter(query, filters);
|
|
3482
|
+
const doc = await collection.findOne(query);
|
|
3448
3483
|
if (!doc) return null;
|
|
3449
3484
|
return transformExperimentRow(doc);
|
|
3450
3485
|
} catch (error) {
|
|
@@ -3519,12 +3554,20 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
|
|
|
3519
3554
|
);
|
|
3520
3555
|
}
|
|
3521
3556
|
}
|
|
3522
|
-
async deleteExperiment({ id }) {
|
|
3557
|
+
async deleteExperiment({ id, filters }) {
|
|
3523
3558
|
try {
|
|
3524
|
-
const resultsCollection = await this.getCollection(TABLE_EXPERIMENT_RESULTS);
|
|
3525
|
-
await resultsCollection.deleteMany({ experimentId: id });
|
|
3526
3559
|
const experimentsCollection = await this.getCollection(TABLE_EXPERIMENTS);
|
|
3527
|
-
|
|
3560
|
+
const gateQuery = { id };
|
|
3561
|
+
applyTenancyFilter(gateQuery, filters);
|
|
3562
|
+
const existing = await experimentsCollection.findOne(gateQuery);
|
|
3563
|
+
if (!existing) return;
|
|
3564
|
+
const resultsCollection = await this.getCollection(TABLE_EXPERIMENT_RESULTS);
|
|
3565
|
+
const resultsQuery = { experimentId: id };
|
|
3566
|
+
applyTenancyFilter(resultsQuery, filters);
|
|
3567
|
+
await resultsCollection.deleteMany(resultsQuery);
|
|
3568
|
+
const parentDeleteQuery = { id };
|
|
3569
|
+
applyTenancyFilter(parentDeleteQuery, filters);
|
|
3570
|
+
await experimentsCollection.deleteOne(parentDeleteQuery);
|
|
3528
3571
|
} catch (error) {
|
|
3529
3572
|
throw new MastraError(
|
|
3530
3573
|
{
|
|
@@ -3643,10 +3686,15 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
|
|
|
3643
3686
|
);
|
|
3644
3687
|
}
|
|
3645
3688
|
}
|
|
3646
|
-
async getExperimentResultById({
|
|
3689
|
+
async getExperimentResultById({
|
|
3690
|
+
id,
|
|
3691
|
+
filters
|
|
3692
|
+
}) {
|
|
3647
3693
|
try {
|
|
3648
3694
|
const collection = await this.getCollection(TABLE_EXPERIMENT_RESULTS);
|
|
3649
|
-
const
|
|
3695
|
+
const query = { id };
|
|
3696
|
+
applyTenancyFilter(query, filters);
|
|
3697
|
+
const doc = await collection.findOne(query);
|
|
3650
3698
|
if (!doc) return null;
|
|
3651
3699
|
return transformExperimentResultRow(doc);
|
|
3652
3700
|
} catch (error) {
|
|
@@ -3713,10 +3761,22 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
|
|
|
3713
3761
|
);
|
|
3714
3762
|
}
|
|
3715
3763
|
}
|
|
3716
|
-
async deleteExperimentResults({
|
|
3764
|
+
async deleteExperimentResults({
|
|
3765
|
+
experimentId,
|
|
3766
|
+
filters
|
|
3767
|
+
}) {
|
|
3717
3768
|
try {
|
|
3769
|
+
if (filters?.organizationId !== void 0 || filters?.projectId !== void 0) {
|
|
3770
|
+
const experimentsCollection = await this.getCollection(TABLE_EXPERIMENTS);
|
|
3771
|
+
const gateQuery = { id: experimentId };
|
|
3772
|
+
applyTenancyFilter(gateQuery, filters);
|
|
3773
|
+
const parent = await experimentsCollection.findOne(gateQuery);
|
|
3774
|
+
if (!parent) return;
|
|
3775
|
+
}
|
|
3718
3776
|
const collection = await this.getCollection(TABLE_EXPERIMENT_RESULTS);
|
|
3719
|
-
|
|
3777
|
+
const deleteQuery = { experimentId };
|
|
3778
|
+
applyTenancyFilter(deleteQuery, filters);
|
|
3779
|
+
await collection.deleteMany(deleteQuery);
|
|
3720
3780
|
} catch (error) {
|
|
3721
3781
|
throw new MastraError(
|
|
3722
3782
|
{
|
|
@@ -4878,11 +4938,6 @@ var MongoDBMCPServersStorage = class _MongoDBMCPServersStorage extends MCPServer
|
|
|
4878
4938
|
return result;
|
|
4879
4939
|
}
|
|
4880
4940
|
};
|
|
4881
|
-
function formatDateForMongoDB(date) {
|
|
4882
|
-
return typeof date === "string" ? new Date(date) : date;
|
|
4883
|
-
}
|
|
4884
|
-
|
|
4885
|
-
// src/storage/domains/memory/index.ts
|
|
4886
4941
|
var OM_TABLE = "mastra_observational_memory";
|
|
4887
4942
|
var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends MemoryStorage {
|
|
4888
4943
|
supportsObservationalMemory = true;
|
|
@@ -9267,6 +9322,14 @@ function transformScoreRow(row) {
|
|
|
9267
9322
|
convertTimestamps: true
|
|
9268
9323
|
});
|
|
9269
9324
|
}
|
|
9325
|
+
function applyTenancyFilters(query, filters) {
|
|
9326
|
+
if (filters?.organizationId !== void 0) {
|
|
9327
|
+
query.organizationId = filters.organizationId;
|
|
9328
|
+
}
|
|
9329
|
+
if (filters?.projectId !== void 0) {
|
|
9330
|
+
query.projectId = filters.projectId;
|
|
9331
|
+
}
|
|
9332
|
+
}
|
|
9270
9333
|
var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
9271
9334
|
#connector;
|
|
9272
9335
|
#skipDefaultIndexes;
|
|
@@ -9435,7 +9498,8 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
9435
9498
|
pagination,
|
|
9436
9499
|
entityId,
|
|
9437
9500
|
entityType,
|
|
9438
|
-
source
|
|
9501
|
+
source,
|
|
9502
|
+
filters
|
|
9439
9503
|
}) {
|
|
9440
9504
|
try {
|
|
9441
9505
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -9451,6 +9515,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
9451
9515
|
if (source) {
|
|
9452
9516
|
query.source = source;
|
|
9453
9517
|
}
|
|
9518
|
+
applyTenancyFilters(query, filters);
|
|
9454
9519
|
const collection = await this.getCollection(TABLE_SCORERS);
|
|
9455
9520
|
const total = await collection.countDocuments(query);
|
|
9456
9521
|
if (total === 0) {
|
|
@@ -9494,14 +9559,17 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
9494
9559
|
}
|
|
9495
9560
|
async listScoresByRunId({
|
|
9496
9561
|
runId,
|
|
9497
|
-
pagination
|
|
9562
|
+
pagination,
|
|
9563
|
+
filters
|
|
9498
9564
|
}) {
|
|
9499
9565
|
try {
|
|
9500
9566
|
const { page, perPage: perPageInput } = pagination;
|
|
9501
9567
|
const perPage = normalizePerPage(perPageInput, 100);
|
|
9502
9568
|
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
9569
|
+
const query = { runId };
|
|
9570
|
+
applyTenancyFilters(query, filters);
|
|
9503
9571
|
const collection = await this.getCollection(TABLE_SCORERS);
|
|
9504
|
-
const total = await collection.countDocuments(
|
|
9572
|
+
const total = await collection.countDocuments(query);
|
|
9505
9573
|
if (total === 0) {
|
|
9506
9574
|
return {
|
|
9507
9575
|
scores: [],
|
|
@@ -9514,7 +9582,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
9514
9582
|
};
|
|
9515
9583
|
}
|
|
9516
9584
|
const end = perPageInput === false ? total : start + perPage;
|
|
9517
|
-
let cursor = collection.find(
|
|
9585
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(start);
|
|
9518
9586
|
if (perPageInput !== false) {
|
|
9519
9587
|
cursor = cursor.limit(perPage);
|
|
9520
9588
|
}
|
|
@@ -9544,14 +9612,17 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
9544
9612
|
async listScoresByEntityId({
|
|
9545
9613
|
entityId,
|
|
9546
9614
|
entityType,
|
|
9547
|
-
pagination
|
|
9615
|
+
pagination,
|
|
9616
|
+
filters
|
|
9548
9617
|
}) {
|
|
9549
9618
|
try {
|
|
9550
9619
|
const { page, perPage: perPageInput } = pagination;
|
|
9551
9620
|
const perPage = normalizePerPage(perPageInput, 100);
|
|
9552
9621
|
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
9622
|
+
const query = { entityId, entityType };
|
|
9623
|
+
applyTenancyFilters(query, filters);
|
|
9553
9624
|
const collection = await this.getCollection(TABLE_SCORERS);
|
|
9554
|
-
const total = await collection.countDocuments(
|
|
9625
|
+
const total = await collection.countDocuments(query);
|
|
9555
9626
|
if (total === 0) {
|
|
9556
9627
|
return {
|
|
9557
9628
|
scores: [],
|
|
@@ -9564,7 +9635,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
9564
9635
|
};
|
|
9565
9636
|
}
|
|
9566
9637
|
const end = perPageInput === false ? total : start + perPage;
|
|
9567
|
-
let cursor = collection.find(
|
|
9638
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(start);
|
|
9568
9639
|
if (perPageInput !== false) {
|
|
9569
9640
|
cursor = cursor.limit(perPage);
|
|
9570
9641
|
}
|
|
@@ -9594,13 +9665,15 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
9594
9665
|
async listScoresBySpan({
|
|
9595
9666
|
traceId,
|
|
9596
9667
|
spanId,
|
|
9597
|
-
pagination
|
|
9668
|
+
pagination,
|
|
9669
|
+
filters
|
|
9598
9670
|
}) {
|
|
9599
9671
|
try {
|
|
9600
9672
|
const { page, perPage: perPageInput } = pagination;
|
|
9601
9673
|
const perPage = normalizePerPage(perPageInput, 100);
|
|
9602
9674
|
const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
9603
9675
|
const query = { traceId, spanId };
|
|
9676
|
+
applyTenancyFilters(query, filters);
|
|
9604
9677
|
const collection = await this.getCollection(TABLE_SCORERS);
|
|
9605
9678
|
const total = await collection.countDocuments(query);
|
|
9606
9679
|
if (total === 0) {
|