From 36bb9c6a873dd2dc39056dbc8ec94674ea66494a Mon Sep 17 00:00:00 2001 From: Andy Burke Date: Tue, 15 Jul 2025 00:35:16 -0700 Subject: [PATCH] docs: add some more jsdoc --- cli.ts | 12 ++++++++++++ deno.json | 2 +- fsdb.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/cli.ts b/cli.ts index ec12591..7064b1e 100644 --- a/cli.ts +++ b/cli.ts @@ -1,3 +1,15 @@ +/** + * Command line interface for fsdb. + + * @example + * + * ``` + * > fsdb items create '{ "id": "able-fish-door-tall-wait-dark-dark-nose-tall-very", "value": "test" }' + * > fsdb items get able-fish-door-tall-wait-dark-dark-nose-tall-very + * ``` + * @module +*/ + import { parseArgs } from '@std/cli/parse-args'; import meta from './deno.json' with { type: 'json' }; import * as fsdb from './fsdb.ts'; diff --git a/deno.json b/deno.json index 395a0cf..46be349 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@andyburke/fsdb", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "exports": { ".": "./fsdb.ts", diff --git a/fsdb.ts b/fsdb.ts index a3716fc..a5e66de 100644 --- a/fsdb.ts +++ b/fsdb.ts @@ -1,7 +1,57 @@ /** * We just write to the disk to reduce complexity. + * @example + * + * ```ts + * import * as fsdb from '@andyburke/fsdb'; + * import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers'; + * import { by_character, by_email, by_phone } from '@andyburke/fsdb/organizers'; + * + * type ITEM = { + * id: string; + * email: string; + * phone: string; + * value: string; + * }; + * + * const item_collection: fsdb.FSDB_COLLECTION = new fsdb.FSDB_COLLECTION({ + * name: 'test-03-items', + * root: get_data_dir() + '/test-03-items', + * indexers: { + * email: new FSDB_INDEXER_SYMLINKS({ + * name: 'email', + * field: 'email', + * organize: by_email + * }), + * phone: new FSDB_INDEXER_SYMLINKS({ + * name: 'phone', + * field: 'phone', + * organize: by_phone + * }), + * value: new FSDB_INDEXER_SYMLINKS({ + * name: 'value', + * organize: by_character, + * get_values_to_index: (item: ITEM) => item.value.split(/\W/).filter((word) => word.length > 3), + * to_many: true + * }) + * } + * }); + * + * const item = { + * id: lurid(), + * email: random_email_address(), + * phone: random_phone_number(), + * value: random_sentence() + * }; + * + * const stored_item: ITEM = await item_collection.create(item); + * const fetched_by_email: ITEM = (await item_collection.find({ email: item.email })).map((entry) => entry.load()).shift(); + * const fetched_by_phone: ITEM = (await item_collection.find({ phone: item.phone })).map((entry) => entry.load()).shift(); + * const fetched_by_word_in_value: ITEM = (await item_collection.find({ value: word })).map((entry) => entry.load()).shift(); + * ``` + * * @module - */ +*/ import * as fs from '@std/fs'; import * as path from '@std/path';