From f2edf6f292938043852dea1463ff166e39793499 Mon Sep 17 00:00:00 2001 From: Andy Burke Date: Sun, 22 Jun 2025 22:07:53 -0700 Subject: [PATCH] refactor: export organizers as a group refactor: change how indexers are exported docs: update with some more examples chore: bump version --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ deno.json | 5 ++-- indexers.ts | 4 ++- organizers.ts | 11 +++++++ 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 organizers.ts diff --git a/README.md b/README.md index 8747ab0..da60835 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,88 @@ optimization to the filesystem layer. `collection.delete(T)` - removes an object from the system and the disk `collection.find(criteria)` - find all objects that match the criteria *that have an index* +### Example + +```typescript +import * as fsdb from '@andyburke/fsdb'; +import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers'; +import { by_character, by_email, by_lurid, by_phone } from '@andyburke/fsdb/organizers'; + +type USER = { + id: string; + email: string; + phone: string; + quote: string; +}; + +const item_collection: fsdb.FSDB_COLLECTION = new fsdb.FSDB_COLLECTION({ + name: 'users', + 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 + }), + by_character_test: new FSDB_INDEXER_SYMLINKS({ + name: 'quote_keywords', + organize: by_character, + get_values_to_index: (user: USER) => user.quote.split(/\W/).filter((word) => word.length > 3).map((word) => word.toLowerCase().trim()), + to_many: true + }) + } +}); +``` + +Would create a folder structure of users that looked something like: + +``` + .fsdb/ + users/ + .fsdb.collection.json <-- collection info + able-fish-door/ + able-fish-door-your-deal-fire-unit/ + able-fish-door-your-deal-fire-unit-trip-give-they/ + able-fish-door-your-deal-fire-unit-trip-give-they.json <-- the user + .index.symlink.quote_keywords.chicken <-- points back to an index symlink for quote_keywords + .index.symlink.quote_keywords.contrary + .index.symlink.quote_keywords.first + .index.symlink.quote_keywords.pineapple + .index.symlink.quote_keywords.sensible + .index.symlink.quote_keywords.that + .index.symlink.quote_keywords.unfortunately + .index.symlink.quote_keywords.wrong + .index.symlink.email.took-case-path@grow-hold-such.edu <-- email index reverse symlink + .index.symlink.phone.01.072-902.2106 <-- phone number index reverse symlink + .indexes/ + email/ + edu/ + grow-hold-such.edu/ + took-case-path@grow-hold-such.edu/ + took-case-path@grow-hold-such.edu.json <-- symlink to the user above + phone/ + 01/ + 072/ + 902/ + 072-902-2106/ + 072-902-2106.json <-- symlink to the user above + quote_keywords/ + c/ + ch/ + chi/ + chicken/ + able-fish-door-your-deal-fire-unit-trip-give-they.json <-- symlink to the user above, which has used this keyword in their quote + co/ + con/ + contrary/ + able-fish-door-your-deal-fire-unit-trip-give-they.json <-- symlink to the user above, which has used this keyword in their quote + ... +``` + ## CLI ``` diff --git a/deno.json b/deno.json index cdece19..0a1d3f0 100644 --- a/deno.json +++ b/deno.json @@ -1,11 +1,12 @@ { "name": "@andyburke/fsdb", - "version": "0.1.0", + "version": "0.2.0", "license": "MIT", "exports": { ".": "./fsdb.ts", "./cli": "./cli.ts", - "./indexers": "./indexers.ts" + "./indexers": "./indexers.ts", + "./organizers": "./organizers.ts" }, "tasks": { diff --git a/indexers.ts b/indexers.ts index 678ae4f..056a0a3 100644 --- a/indexers.ts +++ b/indexers.ts @@ -1,3 +1,5 @@ import { FSDB_INDEXER_SYMLINKS } from './indexers/symlinks.ts'; -export default FSDB_INDEXER_SYMLINKS; +export default { + FSDB_INDEXER_SYMLINKS +}; diff --git a/organizers.ts b/organizers.ts new file mode 100644 index 0000000..ccc13e7 --- /dev/null +++ b/organizers.ts @@ -0,0 +1,11 @@ +import by_character from './organizers/by_character.ts'; +import by_email from './organizers/by_email.ts'; +import by_lurid from './organizers/by_lurid.ts'; +import by_phone from './organizers/by_phone.ts'; + +export default { + by_character, + by_email, + by_lurid, + by_phone +};