feat: release 3.0.2
This commit is contained in:
@@ -29,7 +29,17 @@ describe("Collection", { sanitizeOps: false, sanitizeResources: false }, () => {
|
||||
name: string;
|
||||
storage: MemoryStorage;
|
||||
schema: UserSchema;
|
||||
indexes: [{ field: "id"; kind: "primary" }];
|
||||
indexes: [
|
||||
{ field: "id"; kind: "primary" },
|
||||
{
|
||||
field: "emails";
|
||||
kind: "unique";
|
||||
},
|
||||
{
|
||||
field: "name";
|
||||
kind: "shared";
|
||||
},
|
||||
];
|
||||
}>;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -40,25 +50,29 @@ describe("Collection", { sanitizeOps: false, sanitizeResources: false }, () => {
|
||||
field: "id",
|
||||
kind: "primary",
|
||||
},
|
||||
{
|
||||
field: "emails",
|
||||
kind: "unique",
|
||||
},
|
||||
{
|
||||
field: "name",
|
||||
kind: "shared",
|
||||
},
|
||||
]),
|
||||
schema: {
|
||||
id: z.string(),
|
||||
name: z.string().optional(),
|
||||
fullName: z.string().optional(),
|
||||
emails: z.array(z.email()),
|
||||
friends: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
type: z.union([z.literal("family"), z.literal("close")]),
|
||||
}),
|
||||
),
|
||||
age: z.number(),
|
||||
},
|
||||
schema,
|
||||
indexes: [
|
||||
{
|
||||
field: "id",
|
||||
kind: "primary",
|
||||
},
|
||||
{
|
||||
field: "emails",
|
||||
kind: "unique",
|
||||
},
|
||||
{
|
||||
field: "name",
|
||||
kind: "shared",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@@ -239,6 +253,18 @@ describe("Collection", { sanitizeOps: false, sanitizeResources: false }, () => {
|
||||
expect(docs.every((d) => d.age >= 30)).toBe(true);
|
||||
});
|
||||
|
||||
it("should find documents by indexed condition", async () => {
|
||||
const docs = await collection.findMany({ name: "Bob" });
|
||||
expect(docs).toHaveLength(1);
|
||||
expect(docs[0].name).toBe("Bob");
|
||||
});
|
||||
|
||||
it("should find documents by nested indexed condition", async () => {
|
||||
const docs = await collection.findMany({ emails: { $in: ["charlie@test.com"] } });
|
||||
expect(docs).toHaveLength(1);
|
||||
expect(docs[0].emails[0]).toBe("charlie@test.com");
|
||||
});
|
||||
|
||||
it("should support limit option", async () => {
|
||||
const docs = await collection.findMany({}, { limit: 2 });
|
||||
expect(docs).toHaveLength(2);
|
||||
|
||||
@@ -159,7 +159,7 @@ describe("IndexManager", { sanitizeOps: false, sanitizeResources: false }, () =>
|
||||
const user = { id: "u1", email: "a@example.com", group: "staff", name: "Alice", active: true };
|
||||
manager.insert(user);
|
||||
|
||||
const results = manager.getByCondition({ id: "u1" });
|
||||
const results = manager.getByCondition({ id: "u1" }).all();
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results[0]).toEqual(user);
|
||||
});
|
||||
@@ -170,7 +170,7 @@ describe("IndexManager", { sanitizeOps: false, sanitizeResources: false }, () =>
|
||||
const user = { id: "u1", email: "a@example.com", group: "staff", name: "Alice", active: true };
|
||||
manager.insert(user);
|
||||
|
||||
const results = manager.getByCondition({ email: "a@example.com" });
|
||||
const results = manager.getByCondition({ email: "a@example.com" }).all();
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results[0]).toEqual(user);
|
||||
});
|
||||
@@ -186,12 +186,12 @@ describe("IndexManager", { sanitizeOps: false, sanitizeResources: false }, () =>
|
||||
manager.insert(user2);
|
||||
manager.insert(user3);
|
||||
|
||||
const staff = manager.getByCondition({ group: "staff" });
|
||||
const staff = manager.getByCondition({ group: "staff" }).all();
|
||||
expect(staff).toHaveLength(2);
|
||||
expect(staff).toContainEqual(user1);
|
||||
expect(staff).toContainEqual(user2);
|
||||
|
||||
const admin = manager.getByCondition({ group: "admin" });
|
||||
const admin = manager.getByCondition({ group: "admin" }).all();
|
||||
expect(admin).toHaveLength(1);
|
||||
expect(admin[0]).toEqual(user3);
|
||||
});
|
||||
@@ -201,11 +201,14 @@ describe("IndexManager", { sanitizeOps: false, sanitizeResources: false }, () =>
|
||||
|
||||
const user1 = { id: "u1", email: "a@example.com", group: "staff", name: "Alice", active: true };
|
||||
const user2 = { id: "u2", email: "b@example.com", group: "staff", name: "Bob", active: false };
|
||||
|
||||
manager.insert(user1);
|
||||
manager.insert(user2);
|
||||
|
||||
// Lookup by shared + non-indexed field
|
||||
const results = manager.getByCondition({ group: "staff", active: true });
|
||||
|
||||
const results = manager.getByCondition({ group: "staff", active: true }).all();
|
||||
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results[0]).toEqual(user1);
|
||||
});
|
||||
@@ -216,10 +219,10 @@ describe("IndexManager", { sanitizeOps: false, sanitizeResources: false }, () =>
|
||||
const user = { id: "u1", email: "a@example.com", group: "staff", name: "Alice", active: true };
|
||||
manager.insert(user);
|
||||
|
||||
const results = manager.getByCondition({ group: "admin" });
|
||||
const results = manager.getByCondition({ group: "admin" }).all();
|
||||
expect(results).toEqual([]);
|
||||
|
||||
const results2 = manager.getByCondition({ email: "nonexistent@example.com" });
|
||||
const results2 = manager.getByCondition({ email: "nonexistent@example.com" }).all();
|
||||
expect(results2).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user