CatalogItem
cartographer / CatalogItem
Interface: CatalogItem
Section titled “Interface: 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.
Example
Section titled “Example”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');Properties
Section titled “Properties”id:
string
Defined in: types/dynamicWork.ts:90
filePath
Section titled “filePath”filePath:
string
Defined in: types/dynamicWork.ts:91
Methods
Section titled “Methods”getField()
Section titled “getField()”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.
Type Parameters
Section titled “Type Parameters”T
Expected type of the field value
Parameters
Section titled “Parameters”fieldKey
Section titled “fieldKey”string
The field key to retrieve
Returns
Section titled “Returns”T | null
- The field value, or null if not set
Example
Section titled “Example”const title = item.getField<string>('title');const wordCount = item.getField<number>('word-count');const authors = item.getField<string[]>('authors');setField()
Section titled “setField()”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.
Parameters
Section titled “Parameters”fieldKey
Section titled “fieldKey”string
The field key to set
StoredFieldValue
The value to store
Returns
Section titled “Returns”void
Example
Section titled “Example”item.setField('title', 'The Cosmic Horror');item.setField('word-count', 5000);item.setField('authors', ['Lovecraft, H. P.']);hasField()
Section titled “hasField()”hasField(
fieldKey):boolean
Defined in: types/dynamicWork.ts:151
Check if a field has been set (not null/undefined).
Parameters
Section titled “Parameters”fieldKey
Section titled “fieldKey”string
The field key to check
Returns
Section titled “Returns”boolean
- True if field exists and is not null/undefined
getAllFields()
Section titled “getAllFields()”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.
Returns
Section titled “Returns”Record<string, StoredFieldValue>
- Object with all field keys and values
clearFields()
Section titled “clearFields()”clearFields():
void
Defined in: types/dynamicWork.ts:173
Clear all field values.
Useful for resetting an item before reloading data.
Returns
Section titled “Returns”void
toJSON()
Section titled “toJSON()”toJSON():
Record<string,StoredFieldValue|null|string>
Defined in: types/dynamicWork.ts:182
Serialize item to JSON (including id and filePath).
Returns
Section titled “Returns”Record<string, StoredFieldValue | null | string>
- Plain object with id, filePath, and all fields
clone()
Section titled “clone()”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.
Returns
Section titled “Returns”CatalogItem
- A new CatalogItem with same id, filePath, and fields