From 2cc0921f636c8b0e3a2b56faa206d391e28a06e4 Mon Sep 17 00:00:00 2001 From: Bryan Lundberg Date: Sun, 11 May 2025 21:52:44 -0600 Subject: [PATCH 1/2] test: Add test for getStructuredCollections method Add a unit test to verify that getStructuredCollections correctly returns structured collections. This ensures proper functionality and coverage for this method. --- __test__/unit/base/Naro.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/__test__/unit/base/Naro.test.ts b/__test__/unit/base/Naro.test.ts index f398578..b88657d 100644 --- a/__test__/unit/base/Naro.test.ts +++ b/__test__/unit/base/Naro.test.ts @@ -349,5 +349,17 @@ test("clear, should throw an error if has collection identifier", async () => { await expect(async () => await db.clear("users/123")).rejects.toThrowError(); }) +test("getStructuredCollections, should return the structured collections", async () => { + const db = new Naro(dbName); + await db.add("users", { name: faker.person.fullName(), phone: faker.phone.number() }); + await db.add("products", { name: faker.commerce.productName(), price: faker.commerce.price() }); + const collections = db.getStructuredCollections(); + + expect(collections).toEqual({ + users: expect.any(Array), + products: expect.any(Array) + }); +}) + From 3aff3f10735cd765358cb9eca28e40fd2ed132c4 Mon Sep 17 00:00:00 2001 From: Bryan Lundberg Date: Sun, 11 May 2025 21:52:51 -0600 Subject: [PATCH 2/2] feat: Add method to retrieve structured collections Introduce `getStructuredCollections` method to fetch all collections and their documents as a structured object. This enhancement improves database querying by providing a comprehensive overview of stored data. --- src/base/Naro.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/base/Naro.ts b/src/base/Naro.ts index cada89c..f15c3cf 100644 --- a/src/base/Naro.ts +++ b/src/base/Naro.ts @@ -426,6 +426,18 @@ export class Naro { if (collectionId) throw new Error("Collection ID detected. Use delete method instead."); this.core.removeCollection(collectionName); } + + /** + * Retrieves all collections in the database as a structured object. + * Each key in the returned object represents a collection name, + * and the value is an array of documents within that collection. + * + * @return {Record} An object containing all collections + * and their respective documents. + */ + getStructuredCollections(): Record { + return this.core.getStructuredCollections(); + } }