From b3248ae431f7faacceec9c1126a029eedf68bc14 Mon Sep 17 00:00:00 2001 From: Andy Burke Date: Thu, 6 Nov 2025 22:29:46 -0800 Subject: [PATCH] fix: handle queries for non-existent items --- deno.json | 2 +- tests/04_indexing_sanity_checks.test.ts | 5 +++++ utils/walk.ts | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/deno.json b/deno.json index ead199b..c80a57d 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@andyburke/fsdb", - "version": "1.2.2", + "version": "1.2.3", "license": "MIT", "exports": { ".": "./fsdb.ts", diff --git a/tests/04_indexing_sanity_checks.test.ts b/tests/04_indexing_sanity_checks.test.ts index bbb6240..320e41d 100644 --- a/tests/04_indexing_sanity_checks.test.ts +++ b/tests/04_indexing_sanity_checks.test.ts @@ -155,6 +155,11 @@ Deno.test({ asserts.assertEquals(found, random_item); } + const fetched_nonexistent_entries: ITEM[] = (await item_collection.find({ custom_organizing_test: '*&^' })).map((entry) => + entry.load() + ); + asserts.assertEquals(fetched_nonexistent_entries.length, 0); + // leave one item behind so the whole db for this test doesn't get cleaned up so I can hand-review it // for (const item of items.slice(1)) { // await item_collection.delete(item); diff --git a/utils/walk.ts b/utils/walk.ts index 537ca1b..a6cc18e 100644 --- a/utils/walk.ts +++ b/utils/walk.ts @@ -1,3 +1,4 @@ +import * as fs from '@std/fs'; import * as path from '@std/path'; export type WALK_OPTIONS = { @@ -27,6 +28,11 @@ export async function* walk( const entries: WALK_ENTRY[] = []; + const exists: boolean = await fs.exists(root_path); + if (!exists) { + return entries; + } + const root_info: Deno.FileInfo = await Deno.lstat(root_path); if (!root_info.isDirectory) { const entry: WALK_ENTRY = {