ManagedItem
A high-level interface for reading, writing, and synchronizing a single item in GoatDB. Manages the item's state, schema validation, and version history.
Extends: Emitter
Constructor
new ManagedItem(db: GoatDB<US>, path: string)
Methods
activate()
activate(): void
Activates the managed item by attaching a document change listener to the repository. When the document changes, it will trigger a rebase of the item to sync with the latest version. This method is idempotent - calling it multiple times will only attach one listener.
Note: This is an internal method used by GoatDB and should not be called directly by users.
commit()
commit(): Promise<void>
Commits the current state of this item to the database.
This method:
- Normalizes and validates the item
- In debug mode, asserts that the item is valid
- In non-debug mode, silently returns if the item is invalid
- Cancels any pending delayed commits
- If a commit is already in progress, waits for it to complete before retrying
- Executes the commit
deactivate()
deactivate(): void
Deactivates the managed item by removing the document change listener and canceling any pending commits. This method is idempotent - calling it multiple times has no additional effect.
Note: This is an internal method used by GoatDB and should not be called directly by users.
delete()
delete(key: any): boolean
Deletes a key-value pair from this item. If the field has a default value defined in the schema, the field will be set to that default value instead of being deleted.
downloadDebugGraph()
downloadDebugGraph(): void
Downloads a debug graph visualization of the item's network state. The downloaded file is in a format compatible with Cytoscape, a network visualization and analysis tool.
get()
get(key: any): SchemaDataType<S>[K]
Gets the value for the given key from this item.
has()
has(key: any): boolean
Checks if this item has a value for the given key.
readyPromise()
readyPromise(): Promise<void>
Returns a promise that resolves when this managed item is ready to use. If the item is already ready, the promise resolves immediately.
rebase()
rebase(): void
Synchronizes the local item state with the latest version from the repository.
Similar to git rebase, this merges any remote changes into the local in-memory state.
set()
set(key: any, value: SchemaDataType<S>[T]): void
Sets the value for the given key in this item.
setMulti()
setMulti(data: Partial<SchemaDataType<S>>): void
A convenience method for setting several fields and values at once.
Inherited Methods
From Emitter
attach()
, detach()
, detachAll()
, emit()
, mute()
, once()
, resume()
, suspend()
, unmute()
See Emitter for detailed documentation