Skip to content

Commit

Permalink
Fix lint, add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettgu10 committed Dec 20, 2024
1 parent 7089424 commit e63254e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-years-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": major
---

New filter validation logic supporting set and range queries in Vectorize CLI
16 changes: 7 additions & 9 deletions packages/wrangler/src/vectorize/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import type {
} from "../yargs-types";
import type {
VectorizeMatches,
VectorizeMetadataFilterInnerValue,
VectorizeMetadataFilterValue,
VectorizeMetadataRetrievalLevel,
VectorizeQueryOptions,
VectorizeVectorMetadataFilter,
VectorizeVectorMetadataFilterOp,
VectorizeVectorMetadataValue,
} from "./types";

export function options(yargs: CommonYargsArgv) {
Expand Down Expand Up @@ -155,7 +153,9 @@ export async function handler(
logger.log(JSON.stringify(res, null, 2));
}

function validateQueryFilterInnerValue(innerValue: any) {
function validateQueryFilterInnerValue(
innerValue: VectorizeMetadataFilterValue
) {
return ["string", "number", "boolean"].includes(typeof innerValue);
}

Expand All @@ -180,7 +180,7 @@ export function validateQueryFilter(
for (const field in parsedObj) {
if (Object.prototype.hasOwnProperty.call(parsedObj, field)) {
const value = (
parsedObj as Record<string, VectorizeMetadataFilterValue>
parsedObj as Record<string, VectorizeVectorMetadataFilter>
)[field];

if (Array.isArray(value)) {
Expand All @@ -190,12 +190,12 @@ export function validateQueryFilter(

if (typeof value === "object" && value !== null) {
// Handle nested objects
const innerObj: any = {};
const innerObj: VectorizeVectorMetadataFilter = {};
let validInnerObj = true;

for (const op in value) {
if (Object.prototype.hasOwnProperty.call(value, op)) {
const innerValue = (value as any)[op];
const innerValue = value[op];
if (["$eq", "$ne", "$lt", "$lte", "$gt", "gte"].includes(op)) {
if (!validateQueryFilterInnerValue(innerValue)) {
validInnerObj = false;
Expand All @@ -204,9 +204,7 @@ export function validateQueryFilter(
if (!Array.isArray(innerValue)) {
validInnerObj = false;
} else {
if (
!(innerValue as any[]).every(validateQueryFilterInnerValue)
) {
if (!innerValue.every(validateQueryFilterInnerValue)) {
validInnerObj = false;
}
}
Expand Down

0 comments on commit e63254e

Please sign in to comment.