docs: add some more jsdoc

This commit is contained in:
Andy Burke 2025-07-15 00:35:16 -07:00
parent 55a73c3d0a
commit 36bb9c6a87
3 changed files with 64 additions and 2 deletions

52
fsdb.ts
View file

@ -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<ITEM> = new fsdb.FSDB_COLLECTION<ITEM>({
* name: 'test-03-items',
* root: get_data_dir() + '/test-03-items',
* indexers: {
* email: new FSDB_INDEXER_SYMLINKS<ITEM>({
* name: 'email',
* field: 'email',
* organize: by_email
* }),
* phone: new FSDB_INDEXER_SYMLINKS<ITEM>({
* name: 'phone',
* field: 'phone',
* organize: by_phone
* }),
* value: new FSDB_INDEXER_SYMLINKS<ITEM>({
* 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';