feature: allow organizing by id within symlink indexes

This commit is contained in:
Andy Burke 2025-11-03 18:59:01 -08:00
parent 02a518667b
commit 77765e9e60
2 changed files with 19 additions and 8 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@andyburke/fsdb",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",
"exports": {
".": "./fsdb.ts",
@ -8,16 +8,16 @@
"./indexers": "./indexers.ts",
"./organizers": "./organizers.ts"
},
"tasks": {
"lint": "deno lint",
"fmt": "deno fmt",
"test": "cd tests && DENO_ENV=test FSDB_TEST_DATA_STORAGE_ROOT=./data/$(date --iso-8601=seconds) deno test --allow-env --allow-read --allow-write --fail-fast --trace-leaks ./",
"fsdb": "deno run --allow-env --allow-read --allow-write cli.ts"
},
"fmt": {
"include": ["**/*.ts"],
"include": [
"**/*.ts"
],
"options": {
"useTabs": true,
"lineWidth": 140,
@ -28,10 +28,16 @@
}
},
"lint": {
"include": ["**/*.ts"],
"include": [
"**/*.ts"
],
"rules": {
"tags": ["recommended"],
"exclude": ["no-explicit-any"]
"tags": [
"recommended"
],
"exclude": [
"no-explicit-any"
]
}
},
"imports": {

View file

@ -14,6 +14,7 @@ interface FSDB_INDEXER_SYMLINKS_CONFIG_SHARED {
id_field?: string;
to_many?: boolean;
organize?: (value: string) => string[];
organize_id?: (value: string) => string[];
}
interface FSDB_INDEXER_SYMLINKS_CONFIG_WITH_FIELD extends FSDB_INDEXER_SYMLINKS_CONFIG_SHARED {
@ -191,8 +192,12 @@ export class FSDB_INDEXER_SYMLINKS<T> implements FSDB_INDEXER<T> {
continue;
}
if (this.config.organize_id) {
organized_paths.push(...this.config.organize_id(item_id));
} else {
organized_paths.push(`${item_id}.json`);
}
}
const symlink_path = path.resolve(path.join(this.config.root, ...organized_paths));
const item_dir = path.dirname(authoritative_path);