refactor: export organizers as a group

refactor: change how indexers are exported
docs: update with some more examples
chore: bump version
This commit is contained in:
Andy Burke 2025-06-22 22:07:53 -07:00
parent d9dd449927
commit f2edf6f292
4 changed files with 99 additions and 3 deletions

View file

@ -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<USER> = new fsdb.FSDB_COLLECTION<USER>({
name: 'users',
indexers: {
email: new FSDB_INDEXER_SYMLINKS<USER>({
name: 'email',
field: 'email',
organize: by_email
}),
phone: new FSDB_INDEXER_SYMLINKS<USER>({
name: 'phone',
field: 'phone',
organize: by_phone
}),
by_character_test: new FSDB_INDEXER_SYMLINKS<USER>({
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
```

View file

@ -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": {

View file

@ -1,3 +1,5 @@
import { FSDB_INDEXER_SYMLINKS } from './indexers/symlinks.ts';
export default FSDB_INDEXER_SYMLINKS;
export default {
FSDB_INDEXER_SYMLINKS
};

11
organizers.ts Normal file
View file

@ -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
};