Skip to content

CatalogItem

cartographer


cartographer / CatalogItem

Defined in: types/dynamicWork.ts:89

CatalogItem represents a single work/document in a library catalog.

Uses dynamic field storage to support any schema configuration. Field values are type-checked at runtime based on schema definition.

const item = new CatalogItem('work-001', 'pulp-fiction/works/my-story.md');
item.setField('title', 'The Cosmic Horror');
item.setField('authors', ['Lovecraft, H. P.']);
const title = item.getField<string>('title');

id: string

Defined in: types/dynamicWork.ts:90


filePath: string

Defined in: types/dynamicWork.ts:91

getField<T>(fieldKey): T | null

Defined in: types/dynamicWork.ts:119

Get a field value with optional type coercion.

Returns null if field is not set or has a null/undefined value.

T

Expected type of the field value

string

The field key to retrieve

T | null

  • The field value, or null if not set
const title = item.getField<string>('title');
const wordCount = item.getField<number>('word-count');
const authors = item.getField<string[]>('authors');

setField(fieldKey, value): void

Defined in: types/dynamicWork.ts:141

Set a field value.

Can be used to update any field. The actual type validation should be performed by the caller or the data loading layer.

string

The field key to set

StoredFieldValue

The value to store

void

item.setField('title', 'The Cosmic Horror');
item.setField('word-count', 5000);
item.setField('authors', ['Lovecraft, H. P.']);

hasField(fieldKey): boolean

Defined in: types/dynamicWork.ts:151

Check if a field has been set (not null/undefined).

string

The field key to check

boolean

  • True if field exists and is not null/undefined

getAllFields(): Record<string, StoredFieldValue>

Defined in: types/dynamicWork.ts:164

Get all fields as a plain object.

Useful for exporting or passing to other functions. Returns a shallow copy of the internal fields object.

Record<string, StoredFieldValue>

  • Object with all field keys and values

clearFields(): void

Defined in: types/dynamicWork.ts:173

Clear all field values.

Useful for resetting an item before reloading data.

void


toJSON(): Record<string, StoredFieldValue | null | string>

Defined in: types/dynamicWork.ts:182

Serialize item to JSON (including id and filePath).

Record<string, StoredFieldValue | null | string>

  • Plain object with id, filePath, and all fields

clone(): CatalogItem

Defined in: types/dynamicWork.ts:197

Create a shallow copy of this item.

Useful for filtering operations that need to return new instances.

CatalogItem

  • A new CatalogItem with same id, filePath, and fields