@mastra/upstash 1.6.0 → 1.6.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/dist/index.js CHANGED
@@ -2502,31 +2502,20 @@ var UpstashFilterTranslator = class extends BaseFilterTranslator {
2502
2502
  default: throw new Error(`Unsupported operator: ${operator}`);
2503
2503
  }
2504
2504
  }
2505
- NEGATED_OPERATORS = {
2506
- $eq: "$ne",
2507
- $ne: "$eq",
2508
- $gt: "$lte",
2509
- $gte: "$lt",
2510
- $lt: "$gte",
2511
- $lte: "$gt",
2512
- $in: "$nin",
2513
- $nin: "$in",
2514
- $exists: "$exists"
2515
- };
2516
2505
  formatNot(path, value) {
2517
2506
  if (typeof value !== "object") return `${path} != ${this.formatValue(value)}`;
2518
- if (!Object.keys(value).some((k) => k.startsWith("$"))) {
2519
- const [fieldName, fieldValue] = Object.entries(value)[0] ?? [];
2520
- if (typeof fieldValue === "object" && fieldValue !== null && Object.keys(fieldValue)[0]?.startsWith("$")) {
2521
- const [op, val] = Object.entries(fieldValue)[0] ?? [];
2522
- const negatedOp = this.NEGATED_OPERATORS[op];
2523
- if (!negatedOp) throw new Error(`Unsupported operator in NOT: ${op}`);
2524
- if (op === "$exists") return this.translateOperator(op, !val, fieldName ?? "");
2525
- return this.translateOperator(negatedOp, val, fieldName ?? "");
2526
- }
2527
- return `${fieldName} != ${this.formatValue(fieldValue)}`;
2507
+ const negated = Object.entries(value).map(([key, val]) => key.startsWith("$") ? this.negateOperator(path, key, val) : this.negateField(path ? `${path}.${key}` : key, val));
2508
+ return negated.length > 1 ? `(${negated.join(" OR ")})` : negated[0] ?? "";
2509
+ }
2510
+ negateField(fieldName, fieldValue) {
2511
+ if (Array.isArray(fieldValue)) return fieldValue.length === 0 ? "(HAS FIELD empty OR HAS NOT FIELD empty)" : `${fieldName} NOT IN (${this.formatArray(fieldValue)})`;
2512
+ if (typeof fieldValue === "object" && fieldValue !== null && Object.keys(fieldValue).length > 0) {
2513
+ const negated = Object.entries(fieldValue).map(([key, val]) => key.startsWith("$") ? this.negateOperator(fieldName, key, val) : this.negateField(`${fieldName}.${key}`, val));
2514
+ return negated.length > 1 ? `(${negated.join(" OR ")})` : negated[0];
2528
2515
  }
2529
- const [op, val] = Object.entries(value)[0] ?? [];
2516
+ return `${fieldName} != ${this.formatValue(fieldValue)}`;
2517
+ }
2518
+ negateOperator(path, op, val) {
2530
2519
  if (op === "$lt") return `${path} >= ${this.formatValue(val)}`;
2531
2520
  if (op === "$lte") return `${path} > ${this.formatValue(val)}`;
2532
2521
  if (op === "$gt") return `${path} <= ${this.formatValue(val)}`;
@@ -2538,16 +2527,21 @@ var UpstashFilterTranslator = class extends BaseFilterTranslator {
2538
2527
  if (op === "$in") return `${path} NOT IN (${this.formatArray(val)})`;
2539
2528
  if (op === "$nin") return `${path} IN (${this.formatArray(val)})`;
2540
2529
  if (op === "$exists") return val ? `HAS NOT FIELD ${path}` : `HAS FIELD ${path}`;
2530
+ if (op === "$all") {
2531
+ if (!Array.isArray(val) || val.length === 0) return "(HAS FIELD empty AND HAS NOT FIELD empty)";
2532
+ const negated = val.map((item) => `${path} NOT CONTAINS ${this.formatValue(item)}`);
2533
+ return negated.length > 1 ? `(${negated.join(" OR ")})` : negated[0];
2534
+ }
2541
2535
  if (op === "$and" || op === "$or") {
2542
2536
  const newOp = op === "$and" ? "$or" : "$and";
2543
- const conditions = val.map((condition) => {
2544
- const [fieldName, fieldValue] = Object.entries(condition)[0] ?? [];
2545
- return { [fieldName]: { $not: fieldValue } };
2546
- });
2537
+ const conditions = val.map((condition) => path ? { [path]: { $not: condition } } : { $not: condition });
2547
2538
  return this.translateOperator(newOp, conditions, "");
2548
2539
  }
2549
- if (op === "$nor") return this.translateOperator("$or", val, "");
2550
- return `${path} != ${this.formatValue(val)}`;
2540
+ if (op === "$nor") {
2541
+ const conditions = val.map((condition) => path ? { [path]: condition } : condition);
2542
+ return this.translateOperator("$or", conditions, "");
2543
+ }
2544
+ throw new Error(`Unsupported operator in NOT: ${op}`);
2551
2545
  }
2552
2546
  formatValue(value) {
2553
2547
  if (value === null || value === void 0) throw new Error("Filtering for null/undefined values is not supported by Upstash Vector");