Summary
When using a function predicate on a field whose schema type is z.array(...), the predicate appears to be ignored entirely — findMany returns all records regardless of whether the predicate function would return true or false. Predicates on non-array fields (e.g. strings) work correctly.
Reproduction
import { Collection } from '@msw/data';
import { z } from 'zod';
const users = new Collection({
schema: z.object({
id: z.number(),
name: z.string(),
petNames: z.array(z.string()),
}),
});
await users.create({
id: 1,
name: 'user 1',
petNames: ['wolfy'],
});
await users.create({
id: 2,
name: 'user 2',
petNames: [],
});
// incorrect: returns both records, should return only user 1
users.findMany((q) => q.where({ petNames: (petNames) => petNames.length > 0 }));
// incorrect: returns both records, should return only user 1
users.findMany((q) =>
q.where({ petNames: (petNames) => petNames.includes('wolfy') })
);
// correct: returns only user 2, as expected
console.log(
users.findMany((q) => q.where({ name: (name) => name == 'user 2' }))
);
Expected behavior
The first two findMany calls should each return only the single matching record (user 1), since the predicate function evaluates to false for user 2 (empty array).
Actual behavior
Both queries return all records in the collection, as if the predicate on the petNames field is not being invoked/applied at all.
Environment
@msw/data: 1.1.7
Zod: 4.4.3
Summary
When using a function predicate on a field whose schema type is
z.array(...), the predicate appears to be ignored entirely —findManyreturns all records regardless of whether the predicate function would returntrueorfalse. Predicates on non-array fields (e.g. strings) work correctly.Reproduction
Expected behavior
The first two
findManycalls should each return only the single matching record (user 1), since the predicate function evaluates tofalseforuser 2(empty array).Actual behavior
Both queries return all records in the collection, as if the predicate on the
petNamesfield is not being invoked/applied at all.Environment
@msw/data: 1.1.7Zod: 4.4.3