Skip to main content

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 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:33

Parameters

ParameterType
dbGoatDB<US>
pathstring

Returns

ManagedItem<S, US>

Overrides

Emitter.constructor

Properties

PropertyModifierTypeInherited fromDefined in
alwaysActivereadonlybooleanEmitter.alwaysActivebase/emitter.ts:9
dbreadonlyGoatDB<US>-db/managed-item.ts:33
pathreadonlystring-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

Emitter.isActive


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

ParameterType
eE
cC

Returns

(): void

Returns

void

Inherited from

Emitter.attach


commit()

commit(): Promise<void>

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

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

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

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:123

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:154

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: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

ParameterType
eE
...argsunknown[]

Returns

void

Inherited from

Emitter.emit


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

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:158

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:195

Returns

void

Inherited from

Emitter.mute


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

ParameterType
eE
cC

Returns

(): void

Returns

void

Inherited from

Emitter.once


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

protected resume(): void

Defined in: base/emitter.ts:193

Returns

void

Inherited from

Emitter.resume


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

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:193

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:191

Returns

void

Inherited from

Emitter.suspend


unmute()

unmute(): void

Defined in: base/emitter.ts:199

Returns

void

Inherited from

Emitter.unmute