fix: handle queries for non-existent items

This commit is contained in:
Andy Burke 2025-11-06 22:29:46 -08:00
parent 57bc0f18a0
commit b3248ae431
3 changed files with 12 additions and 1 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "@andyburke/fsdb", "name": "@andyburke/fsdb",
"version": "1.2.2", "version": "1.2.3",
"license": "MIT", "license": "MIT",
"exports": { "exports": {
".": "./fsdb.ts", ".": "./fsdb.ts",

View file

@ -155,6 +155,11 @@ Deno.test({
asserts.assertEquals(found, random_item); 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 // 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)) { // for (const item of items.slice(1)) {
// await item_collection.delete(item); // await item_collection.delete(item);

View file

@ -1,3 +1,4 @@
import * as fs from '@std/fs';
import * as path from '@std/path'; import * as path from '@std/path';
export type WALK_OPTIONS<T> = { export type WALK_OPTIONS<T> = {
@ -27,6 +28,11 @@ export async function* walk<T>(
const entries: WALK_ENTRY<T>[] = []; const entries: WALK_ENTRY<T>[] = [];
const exists: boolean = await fs.exists(root_path);
if (!exists) {
return entries;
}
const root_info: Deno.FileInfo = await Deno.lstat(root_path); const root_info: Deno.FileInfo = await Deno.lstat(root_path);
if (!root_info.isDirectory) { if (!root_info.isDirectory) {
const entry: WALK_ENTRY<T> = { const entry: WALK_ENTRY<T> = {