Class: ManagedItem<S, US>
Defined in: db/managed-item.ts:20
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:33
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:9 |
db | readonly | GoatDB<US> | - | db/managed-item.ts:33 |
path | readonly | string | - | db/managed-item.ts:33 |
Accessors
age
Get Signature
get age():
number
Defined in: db/managed-item.ts:148
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:118
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:50
Returns
boolean
Inherited from
isDeleted
Get Signature
get isDeleted():
boolean
Defined in: db/managed-item.ts:126
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:133
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:55
Returns the key of this item within its repository.
Returns
string
ready
Get Signature
get ready():
boolean
Defined in: db/managed-item.ts:63
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:78
Returns the repository that manages this item.
Returns
Repository<MemRepoStorage>
schema
Get Signature
get schema():
S
Defined in: db/managed-item.ts:85
Returns the current schema of this item.
Returns
S
Set Signature
set schema(
s):void
Defined in: db/managed-item.ts:102
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:90
Type Parameters
| Type Parameter |
|---|
C extends Function |
E extends "LoadingFinished" | EmitterEvent | "change" |
Parameters
| Parameter | Type |
|---|---|
e | E |
c | C |
Returns
():
void
Returns
void
Inherited from
commit()
commit():
Promise<void>
Defined in: db/managed-item.ts:230
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
Returns
Promise<void>
A promise that resolves when the commit is complete
delete()
delete<
T>(key):boolean
Defined in: db/managed-item.ts:208
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:123
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:154
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:298
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, ...args):void
Defined in: base/emitter.ts:54
Type Parameters
| Type Parameter |
|---|
E extends "LoadingFinished" | EmitterEvent | "change" |
Parameters
| Parameter | Type |
|---|---|
e | E |
...args | unknown[] |
Returns
void
Inherited from
get()
get<
K>(key):SchemaDataType<S>[K]
Defined in: db/managed-item.ts:168
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:158
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:195
Returns
void
Inherited from
once()
once<
C,E>(e,c): () =>void
Defined in: base/emitter.ts:182
Type Parameters
| Type Parameter |
|---|
C extends Function |
E extends "LoadingFinished" | EmitterEvent | "change" |
Parameters
| Parameter | Type |
|---|---|
e | E |
c | C |
Returns
():
void
Returns
void
Inherited from
readyPromise()
readyPromise():
Promise<void>
Defined in: db/managed-item.ts:71
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:265
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:193
Returns
void
Inherited from
set()
set<
T>(key,value):void
Defined in: db/managed-item.ts:180
Sets the value for the given key in this item.
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:193
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:191
Returns
void
Inherited from
unmute()
unmute():
void
Defined in: base/emitter.ts:199
Returns
void