diff --git a/deno.json b/deno.json index 17ad92e..cdece19 100644 --- a/deno.json +++ b/deno.json @@ -1,10 +1,11 @@ { "name": "@andyburke/fsdb", - "version": "0.0.2", + "version": "0.1.0", "license": "MIT", "exports": { ".": "./fsdb.ts", - "./cli": "./cli.ts" + "./cli": "./cli.ts", + "./indexers": "./indexers.ts" }, "tasks": { diff --git a/fsdb.ts b/fsdb.ts index b6bb7b9..3a2f1d6 100644 --- a/fsdb.ts +++ b/fsdb.ts @@ -24,6 +24,7 @@ export interface FSDB_INDEXER { lookup(value: string, options?: FSDB_SEARCH_OPTIONS): Promise; } +/** Represents a collection of like items within the database on disk. */ export class FSDB_COLLECTION> { private config: FSDB_COLLECTION_CONFIG; public INDEX: Record>; @@ -84,6 +85,7 @@ export class FSDB_COLLECTION> { Deno.writeTextFileSync(collection_info_file_path, collection_info_json); } + /** Get the "organized" path for the given item within the database. */ public get_organized_item_path(item: any, id_field?: string): string { const id: string = item[id_field ?? this.config.id_field]; const path_elements: string[] = this.config.organize(id); @@ -91,6 +93,7 @@ export class FSDB_COLLECTION> { return resolved_item_path; } + /** Get the "organized" path for the given id within the database. */ public get_organized_id_path(id: string): string { return this.get_organized_item_path({ id }, 'id'); } @@ -114,6 +117,7 @@ export class FSDB_COLLECTION> { } } + /** Get an item from the collection given its id. */ async get(id: string): Promise { const id_path: string = this.get_organized_id_path(id); const item_exists: boolean = await fs.exists(id_path); @@ -126,6 +130,7 @@ export class FSDB_COLLECTION> { return JSON.parse(content); } + /** Create an item in the collection. */ async create(item: T): Promise { const item_path: string = this.get_organized_item_path(item); const item_exists: boolean = await fs.exists(item_path); @@ -141,6 +146,7 @@ export class FSDB_COLLECTION> { return item; } + /** Update the given item in the collection, requiring the id to be stable. */ async update(item: T): Promise { const item_path: string = this.get_organized_item_path(item); const item_exists: boolean = await fs.exists(item_path); @@ -156,6 +162,7 @@ export class FSDB_COLLECTION> { return item; } + /** Delete the given item from the collection. */ async delete(item: T): Promise { const item_path = this.get_organized_item_path(item); const item_exists = await fs.exists(item_path); @@ -192,6 +199,7 @@ export class FSDB_COLLECTION> { return item; } + /** Use indexes to search for matching items. */ async find(criteria: Record, input_options?: FSDB_SEARCH_OPTIONS): Promise { if (Deno.env.get('FSDB_PERF')) performance.mark('fsdb_find_begin'); diff --git a/indexers.ts b/indexers.ts new file mode 100644 index 0000000..678ae4f --- /dev/null +++ b/indexers.ts @@ -0,0 +1,3 @@ +import { FSDB_INDEXER_SYMLINKS } from './indexers/symlinks.ts'; + +export default FSDB_INDEXER_SYMLINKS;