Class: ManagedItem<S, US>
Defined in: db/managed-item.ts:26
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<"change"|"LoadingFinished">
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
S extends Schema | Schema | The schema type for this item |
US extends Schema | Schema | User schema type for the database |
Constructors
Constructor
new ManagedItem<
S,US>(db,path):ManagedItem<S,US>
Defined in: db/managed-item.ts:46
Parameters
| Parameter | Type |
|---|---|
db | GoatDB<US> |
path | string |
Returns
ManagedItem<S, US>
Overrides
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
_idleTimer? | protected | Timer | Optional one-shot idle timer owned by subclasses (Repository, Query) that implement inactivity auto-close. The shared listener hook below keeps it unscheduled whenever a DocumentChanged listener is registered. | Emitter._idleTimer | base/emitter.ts:25 |
alwaysActive | readonly | boolean | - | Emitter.alwaysActive | base/emitter.ts:10 |
db | readonly | GoatDB<US> | - | - | db/managed-item.ts:46 |
path | readonly | string | - | - | db/managed-item.ts:46 |
Accessors
age
Get Signature
get age():
number
Defined in: db/managed-item.ts:196
Returns the age of this item, which is a monotonically increasing number that reflects the order in which commits were received locally. Age numbers are local to each peer and are never synchronized across the network.
Returns
number
The local age number of this item
exists
Get Signature
get exists():
boolean
Defined in: db/managed-item.ts:156
Returns whether this item exists in the repository. An item exists if it has a non-null schema namespace. Items with a null schema cannot be persisted and act as temporary in-memory representations before being properly created with a schema.
Returns
boolean
isActive
Get Signature
get isActive():
boolean
Defined in: base/emitter.ts:63
Returns
boolean
Inherited from
isDeleted
Get Signature
get isDeleted():
boolean
Defined in: db/managed-item.ts:164
Returns whether this item has been deleted and is waiting to be garbage collected at a later time.
Returns
boolean
Set Signature
set isDeleted(
flag):void
Defined in: db/managed-item.ts:171
Sets this item's delete marker. Used to delete/un-delete an item.
Parameters
| Parameter | Type |
|---|---|
flag | boolean |
Returns
void
key
Get Signature
get key():
string
Defined in: db/managed-item.ts:84
Returns the key of this item within its repository.
Returns
string
ready
Get Signature
get ready():
boolean
Defined in: db/managed-item.ts:92
Returns whether this managed item is ready to use. An item is ready when its initial loading from the repository is complete.
Returns
boolean
repository
Get Signature
get repository():
Repository<MemRepoStorage>
Defined in: db/managed-item.ts:107
Returns the repository that manages this item.
Returns
Repository<MemRepoStorage>
schema
Get Signature
get schema():
S
Defined in: db/managed-item.ts:114
Returns the current schema of this item.
Returns
S
Set Signature
set schema(
s):void
Defined in: db/managed-item.ts:131
Updates the schema for this item. Changing an item's schema is allowed under the following limitations:
-
A null item can have its schema changed to any other schema.
-
An item with a non-null schema, may only have its schema upgraded, that is the provided schema must have the same namespace and its version must be greater than the current schema's version.
Explicitly setting the schema is usually done only when creating a new item.
Parameters
| Parameter | Type |
|---|---|
s | S |
Returns
void
Methods
_onListenersChanged()
protected_onListenersChanged(event):void
Defined in: base/emitter.ts:321
Hook called whenever listeners change for a specific event (attach, detach,
or detachAll). The event argument is the event whose listener set changed,
or undefined for detachAll() with no argument. The default implementation
keeps a subclass-owned _idleTimer in sync with DocumentChanged pins;
_touchIdle() is the subclass-specific reset policy.
Parameters
| Parameter | Type |
|---|---|
event | string |
Returns
void
Inherited from
_touchIdle()
protected_touchIdle():void
Defined in: base/emitter.ts:338
Idle-timer reset hook. Subclasses that own an _idleTimer override this;
the default is a no-op.
Returns
void
Inherited from
attach()
attach<
C,E>(e,c): () =>void
Defined in: base/emitter.ts:139
Type Parameters
| Type Parameter |
|---|
C extends Function |
E extends "LoadingFinished" | EmitterEvent | "change" |
Parameters
| Parameter | Type |
|---|---|
e | E |
c | C |
Returns
() => void
Inherited from
commit()
commit():
Promise<void>
Defined in: db/managed-item.ts:304
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
commit() writes to the local log. Call db.flushAll() for full disk
durability.
Returns
Promise<void>
A promise that resolves when the commit is complete
delete()
delete<
T>(key):boolean
Defined in: db/managed-item.ts:269
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.
Type Parameters
| Type Parameter |
|---|
T extends string | number | symbol |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string & T | The key to delete |
Returns
boolean
True if the key was deleted or reset to its default value, false if it didn't exist
detach()
detach<
C,E>(e,c):void
Defined in: base/emitter.ts:173
Type Parameters
| Type Parameter |
|---|
C extends Function |
E extends "LoadingFinished" | EmitterEvent | "change" |
Parameters
| Parameter | Type |
|---|---|
e | E |
c | C |
Returns
void
Inherited from
detachAll()
detachAll<
E>(e?):void
Defined in: base/emitter.ts:214
Type Parameters
| Type Parameter |
|---|
E extends "LoadingFinished" | EmitterEvent | "change" |
Parameters
| Parameter | Type |
|---|---|
e? | E |
Returns
void
Inherited from
downloadDebugGraph()
downloadDebugGraph():
void
Defined in: db/managed-item.ts:378
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.
Returns
void
emit()
emit<
E>(e,a0?,a1?):void
Defined in: base/emitter.ts:88
Emits an event to all registered listeners in registration (FIFO) order. This ordering is a stable contract -- chained query listeners depend on it.
Type Parameters
| Type Parameter |
|---|
E extends "LoadingFinished" | EmitterEvent | "change" |
Parameters
| Parameter | Type |
|---|---|
e | E |
a0? | unknown |
a1? | unknown |
Returns
void
Inherited from
get()
get<
K>(key):SchemaDataType<S>[K]
Defined in: db/managed-item.ts:216
Gets the value for the given key from this item.
Type Parameters
| Type Parameter |
|---|
K extends string | number | symbol |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | K & string | The key to get the value for |
Returns
SchemaDataType<S>[K]
The value associated with the key
has()
has<
T>(key):boolean
Defined in: db/managed-item.ts:206
Checks if this item has a value for the given key.
Type Parameters
| Type Parameter |
|---|
T extends string | number | symbol |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string & T | The key to check for |
Returns
boolean
True if the item has a value for the key, false otherwise
mute()
mute():
void
Defined in: base/emitter.ts:344
Returns
void
Inherited from
once()
once<
C,E>(e,c): () =>void
Defined in: base/emitter.ts:278
Type Parameters
| Type Parameter |
|---|
C extends Function |
E extends "LoadingFinished" | EmitterEvent | "change" |
Parameters
| Parameter | Type |
|---|---|
e | E |
c | C |
Returns
() => void
Inherited from
readyPromise()
readyPromise():
Promise<void>
Defined in: db/managed-item.ts:100
Returns a promise that resolves when this managed item is ready to use. If the item is already ready, the promise resolves immediately.
Returns
Promise<void>
rebase()
rebase():
void
Defined in: db/managed-item.ts:345
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.
Returns
void
resume()
protectedresume():void
Defined in: base/emitter.ts:342
Returns
void
Inherited from
set()
set<
T>(key,value):void
Defined in: db/managed-item.ts:231
Sets the value for the given key in this item.
Changes are coalesced and committed after ~300ms. Call commit() for
immediate persistence.
Type Parameters
| Type Parameter |
|---|
T extends string | number | symbol |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string & T | The key to set the value for |
value | SchemaDataType<S>[T] | The value to associate with the key |
Returns
void
setMulti()
setMulti(
data):void
Defined in: db/managed-item.ts:254
A convenience method for setting several fields and values at once.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | Partial<SchemaDataType<S>> | The values to set. |
Returns
void
suspend()
protectedsuspend():void
Defined in: base/emitter.ts:340
Returns
void
Inherited from
unmute()
unmute():
void
Defined in: base/emitter.ts:348
Returns
void
Inherited from
Events
listenerCount()
listenerCount(
event):number
Defined in: base/emitter.ts:74
Returns the number of live (non-null) callbacks registered for a given event. Used by lifecycle policies (e.g. auto-close) to derive listener 'pins' from the Emitter's own registrations instead of parallel counters, so detachAll / dedup / missing-detach semantics are always respected.
Parameters
| Parameter | Type |
|---|---|
event | "LoadingFinished" | EmitterEvent | "change" |
Returns
number