@mastra/convex 1.9.0 → 1.9.1-alpha.1

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
@@ -2337,6 +2337,25 @@ var ScoresConvex = class extends ScoresStorage {
2337
2337
  }
2338
2338
  };
2339
2339
  // src/storage/domains/workflows/index.ts
2340
+ /**
2341
+ * A stored snapshot reduced to what `listWorkflowRuns({ summary: true })` returns: `status` and
2342
+ * `timestamp` when set, and `parentWorkflow` only when both of its IDs are non-empty strings.
2343
+ * A missing snapshot reduces to `{}`. Reads the stored value in place, without a full copy.
2344
+ */
2345
+ function summarySnapshot(stored) {
2346
+ const parsed = typeof stored === "string" ? JSON.parse(stored) : stored;
2347
+ const { status, timestamp, parentWorkflow } = parsed !== null && typeof parsed === "object" ? parsed : {};
2348
+ const summary = {};
2349
+ if (status !== void 0 && status !== null) summary.status = status;
2350
+ if (timestamp !== void 0 && timestamp !== null) summary.timestamp = timestamp;
2351
+ const workflowId = parentWorkflow?.workflowId;
2352
+ const runId = parentWorkflow?.runId;
2353
+ if (typeof workflowId === "string" && workflowId !== "" && typeof runId === "string" && runId !== "") summary.parentWorkflow = {
2354
+ workflowId,
2355
+ runId
2356
+ };
2357
+ return summary;
2358
+ }
2340
2359
  var WorkflowsConvex = class WorkflowsConvex extends WorkflowsStorage {
2341
2360
  /**
2342
2361
  * Tables `prune()` can clean up. Run ownership records anchor on `updatedAt` (epoch ms), which every
@@ -2441,8 +2460,12 @@ var WorkflowsConvex = class WorkflowsConvex extends WorkflowsStorage {
2441
2460
  if (!row) return null;
2442
2461
  return typeof row.snapshot === "string" ? JSON.parse(row.snapshot) : JSON.parse(JSON.stringify(row.snapshot));
2443
2462
  }
2463
+ /**
2464
+ * Lists runs newest first. With `summary`, each snapshot keeps only its status, timestamp and
2465
+ * parent run; the full rows are still read from Convex.
2466
+ */
2444
2467
  async listWorkflowRuns(args = {}) {
2445
- const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
2468
+ const { workflowName, fromDate, toDate, perPage, page, resourceId, status, summary } = args;
2446
2469
  const filters = [];
2447
2470
  if (workflowName) filters.push({
2448
2471
  field: "workflow_name",
@@ -2469,7 +2492,7 @@ var WorkflowsConvex = class WorkflowsConvex extends WorkflowsStorage {
2469
2492
  runs: rows.map((run) => ({
2470
2493
  workflowName: run.workflow_name,
2471
2494
  runId: run.run_id,
2472
- snapshot: this.ensureSnapshot(run),
2495
+ snapshot: summary ? summarySnapshot(run.snapshot) : this.ensureSnapshot(run),
2473
2496
  createdAt: new Date(run.createdAt),
2474
2497
  updatedAt: new Date(run.updatedAt),
2475
2498
  resourceId: run.resourceId
@@ -2766,38 +2789,29 @@ var ConvexVector = class extends MastraVector {
2766
2789
  if (!value.some((cond) => this.matchesFilterConditions(recordMetadata, cond))) return false;
2767
2790
  continue;
2768
2791
  }
2769
- if (typeof value === "object" && value !== null && "$in" in value) {
2770
- if (!Array.isArray(value.$in) || !value.$in.includes(recordMetadata[key])) return false;
2771
- continue;
2772
- }
2773
- if (typeof value === "object" && value !== null && "$nin" in value) {
2774
- if (Array.isArray(value.$nin) && value.$nin.includes(recordMetadata[key])) return false;
2775
- continue;
2776
- }
2777
- if (typeof value === "object" && value !== null && "$gt" in value) {
2778
- if (!(recordMetadata[key] > value.$gt)) return false;
2779
- continue;
2780
- }
2781
- if (typeof value === "object" && value !== null && "$gte" in value) {
2782
- if (!(recordMetadata[key] >= value.$gte)) return false;
2783
- continue;
2784
- }
2785
- if (typeof value === "object" && value !== null && "$lt" in value) {
2786
- if (!(recordMetadata[key] < value.$lt)) return false;
2787
- continue;
2788
- }
2789
- if (typeof value === "object" && value !== null && "$lte" in value) {
2790
- if (!(recordMetadata[key] <= value.$lte)) return false;
2791
- continue;
2792
- }
2793
- if (typeof value === "object" && value !== null && "$ne" in value) {
2794
- if (recordMetadata[key] === value.$ne) return false;
2792
+ if (typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).some((k) => k.startsWith("$"))) {
2793
+ if (!this.matchesFieldOperators(recordMetadata[key], value)) return false;
2795
2794
  continue;
2796
2795
  }
2797
2796
  if (recordMetadata[key] !== value) return false;
2798
2797
  }
2799
2798
  return true;
2800
2799
  }
2800
+ matchesFieldOperators(fieldValue, operators) {
2801
+ return Object.entries(operators).every(([operator, operand]) => {
2802
+ switch (operator) {
2803
+ case "$eq": return fieldValue === operand;
2804
+ case "$ne": return fieldValue !== operand;
2805
+ case "$in": return Array.isArray(operand) && operand.includes(fieldValue);
2806
+ case "$nin": return !(Array.isArray(operand) && operand.includes(fieldValue));
2807
+ case "$gt": return fieldValue > operand;
2808
+ case "$gte": return fieldValue >= operand;
2809
+ case "$lt": return fieldValue < operand;
2810
+ case "$lte": return fieldValue <= operand;
2811
+ default: return false;
2812
+ }
2813
+ });
2814
+ }
2801
2815
  async callStorage(request) {
2802
2816
  return this.client.callStorage(request);
2803
2817
  }