@mastra/mongodb 1.10.1-alpha.0 → 1.11.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/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.10.1-alpha.0"};
16
+ version: "1.11.0"};
17
17
  var MongoDBFilterTranslator = class extends BaseFilterTranslator {
18
18
  getSupportedOperators() {
19
19
  return {
@@ -1928,7 +1928,22 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
1928
1928
  return [
1929
1929
  { collection: TABLE_DATASETS, keys: { id: 1 }, options: { name: "idx_datasets_id", unique: true } },
1930
1930
  { collection: TABLE_DATASETS, keys: { createdAt: -1, id: 1 }, options: { name: "idx_datasets_createdat_id" } },
1931
+ {
1932
+ collection: TABLE_DATASETS,
1933
+ keys: { organizationId: 1, projectId: 1, createdAt: -1, id: 1 },
1934
+ options: { name: "idx_datasets_tenancy_createdat_id" }
1935
+ },
1936
+ {
1937
+ collection: TABLE_DATASETS,
1938
+ keys: { organizationId: 1, projectId: 1, candidateKey: 1, candidateId: 1 },
1939
+ options: { name: "idx_datasets_tenancy_candidate" }
1940
+ },
1931
1941
  { collection: TABLE_DATASET_ITEMS, keys: { datasetId: 1 }, options: { name: "idx_dataset_items_datasetid" } },
1942
+ {
1943
+ collection: TABLE_DATASET_ITEMS,
1944
+ keys: { organizationId: 1, projectId: 1, datasetId: 1, validTo: 1, isDeleted: 1 },
1945
+ options: { name: "idx_dataset_items_tenancy_list" }
1946
+ },
1932
1947
  {
1933
1948
  collection: TABLE_DATASET_ITEMS,
1934
1949
  keys: { datasetId: 1, validTo: 1 },
@@ -2006,6 +2021,10 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2006
2021
  targetIds: typeof row.targetIds === "string" ? safelyParseJSON(row.targetIds) : row.targetIds ?? void 0,
2007
2022
  scorerIds: typeof row.scorerIds === "string" ? safelyParseJSON(row.scorerIds) : row.scorerIds ?? void 0,
2008
2023
  version: row.version ?? 0,
2024
+ organizationId: row.organizationId ?? null,
2025
+ projectId: row.projectId ?? null,
2026
+ candidateKey: row.candidateKey ?? null,
2027
+ candidateId: row.candidateId ?? null,
2009
2028
  createdAt: ensureDate(row.createdAt),
2010
2029
  updatedAt: ensureDate(row.updatedAt)
2011
2030
  };
@@ -2015,6 +2034,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2015
2034
  id: row.id,
2016
2035
  datasetId: row.datasetId,
2017
2036
  datasetVersion: row.datasetVersion,
2037
+ organizationId: row.organizationId ?? null,
2038
+ projectId: row.projectId ?? null,
2018
2039
  input: typeof row.input === "string" ? safelyParseJSON(row.input) : row.input,
2019
2040
  groundTruth: typeof row.groundTruth === "string" ? safelyParseJSON(row.groundTruth) : row.groundTruth,
2020
2041
  expectedTrajectory: typeof row.expectedTrajectory === "string" ? safelyParseJSON(row.expectedTrajectory) : row.expectedTrajectory,
@@ -2059,6 +2080,10 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2059
2080
  targetIds: input.targetIds ?? null,
2060
2081
  scorerIds: input.scorerIds ?? null,
2061
2082
  version: 0,
2083
+ organizationId: input.organizationId ?? null,
2084
+ projectId: input.projectId ?? null,
2085
+ candidateKey: input.candidateKey ?? null,
2086
+ candidateId: input.candidateId ?? null,
2062
2087
  createdAt: now,
2063
2088
  updatedAt: now
2064
2089
  };
@@ -2169,7 +2194,12 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2169
2194
  try {
2170
2195
  const { page, perPage: perPageInput } = args.pagination;
2171
2196
  const collection = await this.getCollection(TABLE_DATASETS);
2172
- const total = await collection.countDocuments({});
2197
+ const filter = {};
2198
+ if (args.filters?.organizationId !== void 0) filter.organizationId = args.filters.organizationId;
2199
+ if (args.filters?.projectId !== void 0) filter.projectId = args.filters.projectId;
2200
+ if (args.filters?.candidateKey !== void 0) filter.candidateKey = args.filters.candidateKey;
2201
+ if (args.filters?.candidateId !== void 0) filter.candidateId = args.filters.candidateId;
2202
+ const total = await collection.countDocuments(filter);
2173
2203
  if (total === 0) {
2174
2204
  return { datasets: [], pagination: { total: 0, page, perPage: perPageInput, hasMore: false } };
2175
2205
  }
@@ -2179,7 +2209,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2179
2209
  return { datasets: [], pagination: { total, page, perPage: perPageForResponse, hasMore: total > 0 } };
2180
2210
  }
2181
2211
  const limitValue = perPageInput === false ? total : perPage;
2182
- const rows = await collection.find({}).sort({ createdAt: -1, id: 1 }).skip(offset).limit(limitValue).toArray();
2212
+ const rows = await collection.find(filter).sort({ createdAt: -1, id: 1 }).skip(offset).limit(limitValue).toArray();
2183
2213
  return {
2184
2214
  datasets: rows.map((row) => this.transformDatasetRow(row)),
2185
2215
  pagination: {
@@ -2223,10 +2253,14 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2223
2253
  });
2224
2254
  }
2225
2255
  const newVersion = result.version;
2256
+ const organizationId = result.organizationId ?? null;
2257
+ const projectId = result.projectId ?? null;
2226
2258
  await itemsCollection.insertOne({
2227
2259
  id,
2228
2260
  datasetId: args.datasetId,
2229
2261
  datasetVersion: newVersion,
2262
+ organizationId,
2263
+ projectId,
2230
2264
  validTo: null,
2231
2265
  isDeleted: false,
2232
2266
  input: args.input,
@@ -2249,6 +2283,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2249
2283
  id,
2250
2284
  datasetId: args.datasetId,
2251
2285
  datasetVersion: newVersion,
2286
+ organizationId,
2287
+ projectId,
2252
2288
  input: args.input,
2253
2289
  groundTruth: args.groundTruth,
2254
2290
  expectedTrajectory: args.expectedTrajectory,
@@ -2320,6 +2356,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2320
2356
  });
2321
2357
  }
2322
2358
  const newVersion = result.version;
2359
+ const parentOrganizationId = result.organizationId ?? null;
2360
+ const parentProjectId = result.projectId ?? null;
2323
2361
  await itemsCollection.updateOne(
2324
2362
  { id: args.id, validTo: null, isDeleted: false },
2325
2363
  { $set: { validTo: newVersion } }
@@ -2328,6 +2366,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2328
2366
  id: args.id,
2329
2367
  datasetId: args.datasetId,
2330
2368
  datasetVersion: newVersion,
2369
+ organizationId: parentOrganizationId,
2370
+ projectId: parentProjectId,
2331
2371
  validTo: null,
2332
2372
  isDeleted: false,
2333
2373
  input: mergedInput,
@@ -2349,6 +2389,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2349
2389
  return {
2350
2390
  ...existing,
2351
2391
  datasetVersion: newVersion,
2392
+ organizationId: parentOrganizationId,
2393
+ projectId: parentProjectId,
2352
2394
  input: mergedInput,
2353
2395
  groundTruth: mergedGroundTruth,
2354
2396
  expectedTrajectory: mergedExpectedTrajectory,
@@ -2401,15 +2443,21 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2401
2443
  });
2402
2444
  }
2403
2445
  const newVersion = result.version;
2446
+ const parentOrganizationId = result.organizationId ?? null;
2447
+ const parentProjectId = result.projectId ?? null;
2404
2448
  await itemsCollection.updateOne({ id, validTo: null, isDeleted: false }, { $set: { validTo: newVersion } });
2405
2449
  await itemsCollection.insertOne({
2406
2450
  id,
2407
2451
  datasetId,
2408
2452
  datasetVersion: newVersion,
2453
+ organizationId: parentOrganizationId,
2454
+ projectId: parentProjectId,
2409
2455
  validTo: null,
2410
2456
  isDeleted: true,
2411
2457
  input: existing.input,
2412
2458
  groundTruth: existing.groundTruth,
2459
+ expectedTrajectory: existing.expectedTrajectory ?? null,
2460
+ toolMocks: existing.toolMocks ?? null,
2413
2461
  requestContext: existing.requestContext,
2414
2462
  metadata: existing.metadata,
2415
2463
  source: existing.source,
@@ -2472,11 +2520,15 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2472
2520
  });
2473
2521
  }
2474
2522
  const newVersion = result.version;
2523
+ const organizationId = result.organizationId ?? null;
2524
+ const projectId = result.projectId ?? null;
2475
2525
  if (itemsWithIds.length > 0) {
2476
2526
  const docs = itemsWithIds.map(({ generatedId, itemInput }) => ({
2477
2527
  id: generatedId,
2478
2528
  datasetId: input.datasetId,
2479
2529
  datasetVersion: newVersion,
2530
+ organizationId,
2531
+ projectId,
2480
2532
  validTo: null,
2481
2533
  isDeleted: false,
2482
2534
  input: itemInput.input,
@@ -2501,6 +2553,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2501
2553
  id: generatedId,
2502
2554
  datasetId: input.datasetId,
2503
2555
  datasetVersion: newVersion,
2556
+ organizationId,
2557
+ projectId,
2504
2558
  input: itemInput.input,
2505
2559
  groundTruth: itemInput.groundTruth,
2506
2560
  expectedTrajectory: itemInput.expectedTrajectory,
@@ -2561,6 +2615,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2561
2615
  });
2562
2616
  }
2563
2617
  const newVersion = result.version;
2618
+ const parentOrganizationId = result.organizationId ?? null;
2619
+ const parentProjectId = result.projectId ?? null;
2564
2620
  const currentIds = currentItems.map((i) => i.id);
2565
2621
  await itemsCollection.updateMany(
2566
2622
  { id: { $in: currentIds }, validTo: null, isDeleted: false },
@@ -2570,10 +2626,14 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2570
2626
  id: item.id,
2571
2627
  datasetId: input.datasetId,
2572
2628
  datasetVersion: newVersion,
2629
+ organizationId: parentOrganizationId,
2630
+ projectId: parentProjectId,
2573
2631
  validTo: null,
2574
2632
  isDeleted: true,
2575
2633
  input: item.input,
2576
2634
  groundTruth: item.groundTruth,
2635
+ expectedTrajectory: item.expectedTrajectory ?? null,
2636
+ toolMocks: item.toolMocks ?? null,
2577
2637
  requestContext: item.requestContext,
2578
2638
  metadata: item.metadata,
2579
2639
  source: item.source,
@@ -2675,6 +2735,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
2675
2735
  const { page, perPage: perPageInput } = args.pagination;
2676
2736
  const collection = await this.getCollection(TABLE_DATASET_ITEMS);
2677
2737
  const filter = { datasetId: args.datasetId };
2738
+ if (args.filters?.organizationId !== void 0) filter.organizationId = args.filters.organizationId;
2739
+ if (args.filters?.projectId !== void 0) filter.projectId = args.filters.projectId;
2678
2740
  if (args.version !== void 0) {
2679
2741
  filter.datasetVersion = { $lte: args.version };
2680
2742
  filter.$or = [{ validTo: null }, { validTo: { $gt: args.version } }];
@@ -2829,6 +2891,8 @@ function transformExperimentRow(row) {
2829
2891
  metadata: parseJsonField(row.metadata) ?? void 0,
2830
2892
  datasetId: row.datasetId ?? null,
2831
2893
  datasetVersion: row.datasetVersion != null ? Number(row.datasetVersion) : null,
2894
+ organizationId: row.organizationId ?? null,
2895
+ projectId: row.projectId ?? null,
2832
2896
  targetType: row.targetType,
2833
2897
  targetId: row.targetId,
2834
2898
  status: row.status,
@@ -2849,6 +2913,8 @@ function transformExperimentResultRow(row) {
2849
2913
  experimentId: row.experimentId,
2850
2914
  itemId: row.itemId,
2851
2915
  itemDatasetVersion: row.itemDatasetVersion != null ? Number(row.itemDatasetVersion) : null,
2916
+ organizationId: row.organizationId ?? null,
2917
+ projectId: row.projectId ?? null,
2852
2918
  input: parseJsonField(row.input),
2853
2919
  output: parseJsonField(row.output) ?? null,
2854
2920
  groundTruth: parseJsonField(row.groundTruth) ?? null,
@@ -2887,11 +2953,14 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
2887
2953
  { collection: TABLE_EXPERIMENTS, keys: { id: 1 }, options: { unique: true } },
2888
2954
  { collection: TABLE_EXPERIMENTS, keys: { datasetId: 1 } },
2889
2955
  { collection: TABLE_EXPERIMENTS, keys: { createdAt: -1, id: 1 } },
2956
+ // Tenancy: leading-tenant indexes for multi-tenant scans (parity with datasets domain).
2957
+ { collection: TABLE_EXPERIMENTS, keys: { organizationId: 1, projectId: 1 } },
2890
2958
  { collection: TABLE_EXPERIMENT_RESULTS, keys: { id: 1 }, options: { unique: true } },
2891
2959
  { collection: TABLE_EXPERIMENT_RESULTS, keys: { experimentId: 1 } },
2892
2960
  { collection: TABLE_EXPERIMENT_RESULTS, keys: { experimentId: 1, itemId: 1 }, options: { unique: true } },
2893
2961
  { collection: TABLE_EXPERIMENT_RESULTS, keys: { createdAt: -1 } },
2894
- { collection: TABLE_EXPERIMENT_RESULTS, keys: { experimentId: 1, startedAt: 1, id: 1 } }
2962
+ { collection: TABLE_EXPERIMENT_RESULTS, keys: { experimentId: 1, startedAt: 1, id: 1 } },
2963
+ { collection: TABLE_EXPERIMENT_RESULTS, keys: { organizationId: 1, projectId: 1 } }
2895
2964
  ];
2896
2965
  }
2897
2966
  async createDefaultIndexes() {
@@ -2933,6 +3002,8 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
2933
3002
  metadata: input.metadata ?? null,
2934
3003
  datasetId: input.datasetId ?? null,
2935
3004
  datasetVersion: input.datasetVersion ?? null,
3005
+ organizationId: input.organizationId ?? null,
3006
+ projectId: input.projectId ?? null,
2936
3007
  targetType: input.targetType,
2937
3008
  targetId: input.targetId,
2938
3009
  status: "pending",
@@ -2956,6 +3027,8 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
2956
3027
  metadata: input.metadata,
2957
3028
  datasetId: input.datasetId ?? null,
2958
3029
  datasetVersion: input.datasetVersion ?? null,
3030
+ organizationId: input.organizationId ?? null,
3031
+ projectId: input.projectId ?? null,
2959
3032
  targetType: input.targetType,
2960
3033
  targetId: input.targetId,
2961
3034
  status: "pending",
@@ -3057,6 +3130,15 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
3057
3130
  if (args.status) {
3058
3131
  filter.status = args.status;
3059
3132
  }
3133
+ if (args.filters) {
3134
+ const { organizationId, projectId } = args.filters;
3135
+ if (organizationId !== void 0) {
3136
+ filter.organizationId = organizationId;
3137
+ }
3138
+ if (projectId !== void 0) {
3139
+ filter.projectId = projectId;
3140
+ }
3141
+ }
3060
3142
  const total = await collection.countDocuments(filter);
3061
3143
  if (total === 0) {
3062
3144
  return { experiments: [], pagination: { total: 0, page, perPage: perPageInput, hasMore: false } };
@@ -3117,6 +3199,8 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
3117
3199
  experimentId: input.experimentId,
3118
3200
  itemId: input.itemId,
3119
3201
  itemDatasetVersion: input.itemDatasetVersion ?? null,
3202
+ organizationId: input.organizationId ?? null,
3203
+ projectId: input.projectId ?? null,
3120
3204
  input: input.input,
3121
3205
  output: input.output ?? null,
3122
3206
  groundTruth: input.groundTruth ?? null,
@@ -3138,6 +3222,8 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
3138
3222
  experimentId: input.experimentId,
3139
3223
  itemId: input.itemId,
3140
3224
  itemDatasetVersion: input.itemDatasetVersion ?? null,
3225
+ organizationId: input.organizationId ?? null,
3226
+ projectId: input.projectId ?? null,
3141
3227
  input: input.input,
3142
3228
  output: input.output ?? null,
3143
3229
  groundTruth: input.groundTruth ?? null,
@@ -3237,6 +3323,15 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends Experim
3237
3323
  if (args.status) {
3238
3324
  filter.status = args.status;
3239
3325
  }
3326
+ if (args.filters) {
3327
+ const { organizationId, projectId } = args.filters;
3328
+ if (organizationId !== void 0) {
3329
+ filter.organizationId = organizationId;
3330
+ }
3331
+ if (projectId !== void 0) {
3332
+ filter.projectId = projectId;
3333
+ }
3334
+ }
3240
3335
  const total = await collection.countDocuments(filter);
3241
3336
  if (total === 0) {
3242
3337
  return { results: [], pagination: { total: 0, page, perPage: perPageInput, hasMore: false } };
@@ -6874,17 +6969,39 @@ Note: This migration may take some time for large collections.
6874
6969
  supported: ["batch-with-updates", "insert-only"]
6875
6970
  };
6876
6971
  }
6972
+ createDateRangeCondition(field, range) {
6973
+ const dateFilter = {};
6974
+ const stringFilter = {};
6975
+ if (range.start) {
6976
+ const operator = range.startExclusive ? "$gt" : "$gte";
6977
+ const start = range.start instanceof Date ? range.start : new Date(range.start);
6978
+ dateFilter[operator] = start;
6979
+ stringFilter[operator] = start.toISOString();
6980
+ }
6981
+ if (range.end) {
6982
+ const operator = range.endExclusive ? "$lt" : "$lte";
6983
+ const end = range.end instanceof Date ? range.end : new Date(range.end);
6984
+ dateFilter[operator] = end;
6985
+ stringFilter[operator] = end.toISOString();
6986
+ }
6987
+ if (Object.keys(dateFilter).length === 0) {
6988
+ return null;
6989
+ }
6990
+ return {
6991
+ $or: [{ [field]: dateFilter }, { [field]: stringFilter }]
6992
+ };
6993
+ }
6877
6994
  async createSpan(args) {
6878
6995
  const { span } = args;
6879
6996
  try {
6880
- const startedAt = span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt;
6881
- const endedAt = span.endedAt instanceof Date ? span.endedAt.toISOString() : span.endedAt;
6997
+ const startedAt = span.startedAt instanceof Date ? span.startedAt : new Date(span.startedAt);
6998
+ const endedAt = span.endedAt == null ? span.endedAt : span.endedAt instanceof Date ? span.endedAt : new Date(span.endedAt);
6882
6999
  const record = {
6883
7000
  ...span,
6884
7001
  startedAt,
6885
7002
  endedAt,
6886
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
6887
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
7003
+ createdAt: /* @__PURE__ */ new Date(),
7004
+ updatedAt: /* @__PURE__ */ new Date()
6888
7005
  };
6889
7006
  const collection = await this.getCollection(TABLE_SPANS);
6890
7007
  await collection.insertOne(record);
@@ -7019,15 +7136,15 @@ Note: This migration may take some time for large collections.
7019
7136
  const { traceId, spanId, updates } = args;
7020
7137
  try {
7021
7138
  const data = { ...updates };
7022
- if (data.endedAt instanceof Date) {
7023
- data.endedAt = data.endedAt.toISOString();
7139
+ if (data.endedAt != null && !(data.endedAt instanceof Date)) {
7140
+ data.endedAt = new Date(data.endedAt);
7024
7141
  }
7025
- if (data.startedAt instanceof Date) {
7026
- data.startedAt = data.startedAt.toISOString();
7142
+ if (data.startedAt != null && !(data.startedAt instanceof Date)) {
7143
+ data.startedAt = new Date(data.startedAt);
7027
7144
  }
7028
7145
  const updateData = {
7029
7146
  ...data,
7030
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
7147
+ updatedAt: /* @__PURE__ */ new Date()
7031
7148
  };
7032
7149
  const collection = await this.getCollection(TABLE_SPANS);
7033
7150
  await collection.updateOne({ spanId, traceId }, { $set: updateData });
@@ -7059,27 +7176,15 @@ Note: This migration may take some time for large collections.
7059
7176
  const andConditions = [];
7060
7177
  if (filters) {
7061
7178
  if (filters.startedAt) {
7062
- const startedAtFilter = {};
7063
- if (filters.startedAt.start) {
7064
- startedAtFilter.$gte = filters.startedAt.start.toISOString();
7065
- }
7066
- if (filters.startedAt.end) {
7067
- startedAtFilter.$lte = filters.startedAt.end.toISOString();
7068
- }
7069
- if (Object.keys(startedAtFilter).length > 0) {
7070
- mongoFilter.startedAt = startedAtFilter;
7179
+ const startedAtCondition = this.createDateRangeCondition("startedAt", filters.startedAt);
7180
+ if (startedAtCondition) {
7181
+ andConditions.push(startedAtCondition);
7071
7182
  }
7072
7183
  }
7073
7184
  if (filters.endedAt) {
7074
- const endedAtFilter = {};
7075
- if (filters.endedAt.start) {
7076
- endedAtFilter.$gte = filters.endedAt.start.toISOString();
7077
- }
7078
- if (filters.endedAt.end) {
7079
- endedAtFilter.$lte = filters.endedAt.end.toISOString();
7080
- }
7081
- if (Object.keys(endedAtFilter).length > 0) {
7082
- andConditions.push({ endedAt: endedAtFilter });
7185
+ const endedAtCondition = this.createDateRangeCondition("endedAt", filters.endedAt);
7186
+ if (endedAtCondition) {
7187
+ andConditions.push(endedAtCondition);
7083
7188
  }
7084
7189
  }
7085
7190
  if (filters.spanType !== void 0) {
@@ -7287,14 +7392,14 @@ Note: This migration may take some time for large collections.
7287
7392
  async batchCreateSpans(args) {
7288
7393
  try {
7289
7394
  const records = args.records.map((record) => {
7290
- const startedAt = record.startedAt instanceof Date ? record.startedAt.toISOString() : record.startedAt;
7291
- const endedAt = record.endedAt instanceof Date ? record.endedAt.toISOString() : record.endedAt;
7395
+ const startedAt = record.startedAt instanceof Date ? record.startedAt : new Date(record.startedAt);
7396
+ const endedAt = record.endedAt == null ? record.endedAt : record.endedAt instanceof Date ? record.endedAt : new Date(record.endedAt);
7292
7397
  return {
7293
7398
  ...record,
7294
7399
  startedAt,
7295
7400
  endedAt,
7296
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
7297
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
7401
+ createdAt: /* @__PURE__ */ new Date(),
7402
+ updatedAt: /* @__PURE__ */ new Date()
7298
7403
  };
7299
7404
  });
7300
7405
  if (records.length > 0) {
@@ -7319,15 +7424,15 @@ Note: This migration may take some time for large collections.
7319
7424
  }
7320
7425
  const bulkOps = args.records.map((record) => {
7321
7426
  const data = { ...record.updates };
7322
- if (data.endedAt instanceof Date) {
7323
- data.endedAt = data.endedAt.toISOString();
7427
+ if (data.endedAt != null && !(data.endedAt instanceof Date)) {
7428
+ data.endedAt = new Date(data.endedAt);
7324
7429
  }
7325
- if (data.startedAt instanceof Date) {
7326
- data.startedAt = data.startedAt.toISOString();
7430
+ if (data.startedAt != null && !(data.startedAt instanceof Date)) {
7431
+ data.startedAt = new Date(data.startedAt);
7327
7432
  }
7328
7433
  const updateData = {
7329
7434
  ...data,
7330
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
7435
+ updatedAt: /* @__PURE__ */ new Date()
7331
7436
  };
7332
7437
  return {
7333
7438
  updateOne: {