Skip to main content

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 ParameterDefault typeDescription
S extends SchemaSchemaThe schema type for this item
US extends SchemaSchemaUser schema type for the database

Constructors​

Constructor​

new ManagedItem<S, US>(db, path): ManagedItem<S, US>

Defined in: db/managed-item.ts:46

Parameters​

ParameterType
dbGoatDB<US>
pathstring

Returns​

ManagedItem<S, US>

Overrides​

Emitter.constructor

Properties​

PropertyModifierTypeDescriptionInherited fromDefined in
_idleTimer?protectedTimerOptional 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._idleTimerbase/emitter.ts:25
alwaysActivereadonlyboolean-Emitter.alwaysActivebase/emitter.ts:10
dbreadonlyGoatDB<US>--db/managed-item.ts:46
pathreadonlystring--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​

Emitter.isActive


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​
ParameterType
flagboolean
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​
ParameterType
sS
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​

ParameterType
eventstring

Returns​

void

Inherited from​

Emitter._onListenersChanged


_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​

Emitter._touchIdle


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​

ParameterType
eE
cC

Returns​

() => void

Inherited from​

Emitter.attach


commit()​

commit(): Promise<void>

Defined in: db/managed-item.ts:304

Commits the current state of this item to the database.

This method:

  1. Normalizes and validates the item
  2. In debug mode, asserts that the item is valid
  3. In non-debug mode, silently returns if the item is invalid
  4. Cancels any pending delayed commits
  5. If a commit is already in progress, waits for it to complete before retrying
  6. 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​

ParameterTypeDescription
keystring & TThe 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​

ParameterType
eE
cC

Returns​

void

Inherited from​

Emitter.detach


detachAll()​

detachAll<E>(e?): void

Defined in: base/emitter.ts:214

Type Parameters​

Type Parameter
E extends "LoadingFinished" | EmitterEvent | "change"

Parameters​

ParameterType
e?E

Returns​

void

Inherited from​

Emitter.detachAll


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​

ParameterType
eE
a0?unknown
a1?unknown

Returns​

void

Inherited from​

Emitter.emit


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​

ParameterTypeDescription
keyK & stringThe 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​

ParameterTypeDescription
keystring & TThe 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​

Emitter.mute


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​

ParameterType
eE
cC

Returns​

() => void

Inherited from​

Emitter.once


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()​

protected resume(): void

Defined in: base/emitter.ts:342

Returns​

void

Inherited from​

Emitter.resume


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​

ParameterTypeDescription
keystring & TThe key to set the value for
valueSchemaDataType<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​

ParameterTypeDescription
dataPartial<SchemaDataType<S>>The values to set.

Returns​

void


suspend()​

protected suspend(): void

Defined in: base/emitter.ts:340

Returns​

void

Inherited from​

Emitter.suspend


unmute()​

unmute(): void

Defined in: base/emitter.ts:348

Returns​

void

Inherited from​

Emitter.unmute

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​

ParameterType
event"LoadingFinished" | EmitterEvent | "change"

Returns​

number

Inherited from​

Emitter.listenerCount