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", "name": "@andyburke/fsdb",
"version": "1.1.0", "version": "1.2.0",
"license": "MIT", "license": "MIT",
"exports": { "exports": {
".": "./fsdb.ts", ".": "./fsdb.ts",
@ -8,16 +8,16 @@
"./indexers": "./indexers.ts", "./indexers": "./indexers.ts",
"./organizers": "./organizers.ts" "./organizers": "./organizers.ts"
}, },
"tasks": { "tasks": {
"lint": "deno lint", "lint": "deno lint",
"fmt": "deno fmt", "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 ./", "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" "fsdb": "deno run --allow-env --allow-read --allow-write cli.ts"
}, },
"fmt": { "fmt": {
"include": ["**/*.ts"], "include": [
"**/*.ts"
],
"options": { "options": {
"useTabs": true, "useTabs": true,
"lineWidth": 140, "lineWidth": 140,
@ -28,10 +28,16 @@
} }
}, },
"lint": { "lint": {
"include": ["**/*.ts"], "include": [
"**/*.ts"
],
"rules": { "rules": {
"tags": ["recommended"], "tags": [
"exclude": ["no-explicit-any"] "recommended"
],
"exclude": [
"no-explicit-any"
]
} }
}, },
"imports": { "imports": {

View file

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