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:42
Parameters
| Parameter | Type |
|---|---|
db | GoatDB<US> |
path | string |
Returns
ManagedItem<S, US>
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
alwaysActive | readonly | boolean | Emitter.alwaysActive | base/emitter.ts:10 |
db | readonly | GoatDB<US> | - | db/managed-item.ts:42 |
path | readonly | string | - | db/managed-item.ts:42 |
Accessors
age
Get Signature
get age():
number
Defined in: db/managed-item.ts:192
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:152
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:57
Returns
boolean
Inherited from
isDeleted
Get Signature
get isDeleted():
boolean
Defined in: db/managed-item.ts:160
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:167
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:80
Returns the key of this item within its repository.
Returns
string
ready
Get Signature
get ready():
boolean
Defined in: db/managed-item.ts:88
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:103
Returns the repository that manages this item.
Returns
Repository<MemRepoStorage>
schema
Get Signature
get schema():
S
Defined in: db/managed-item.ts:110
Returns the current schema of this item.
Returns
S
Set Signature
set schema(
s):void
Defined in: db/managed-item.ts:127
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
attach()
attach<
C,E>(e,c): () =>void
Defined in: base/emitter.ts:116
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:300
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:265
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:149
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:188
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:374
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:65
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:212
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:202
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:288
Returns
void
Inherited from
once()
once<
C,E>(e,c): () =>void
Defined in: base/emitter.ts:248
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:96
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:341
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:286
Returns
void
Inherited from
set()
set<
T>(key,value):void
Defined in: db/managed-item.ts:227
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:250
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:284
Returns
void
Inherited from
unmute()
unmute():
void
Defined in: base/emitter.ts:292
Returns
void