Skip to main content

Class: Repository<ST>

Defined in: repo/repo.ts:109

Extends

Type Parameters

Type ParameterDefault type
ST extends RepoStorage<ST>MemRepoStorage

Constructors

Constructor

new Repository<ST>(db, path, trustPool, __namedParameters?): Repository<ST>

Defined in: repo/repo.ts:137

Parameters

ParameterType
dbGoatDB
pathstring
trustPoolTrustPool
__namedParametersRepositoryConfig<ST>

Returns

Repository<ST>

Overrides

Emitter.constructor

Properties

PropertyModifierTypeInherited fromDefined in
allowedNamespacesreadonlystring[]-repo/repo.ts:115
alwaysActivereadonlybooleanEmitter.alwaysActivebase/emitter.ts:10
authorizer?readonlyAuthRule-repo/repo.ts:117
dbreadonlyGoatDB-repo/repo.ts:138
pathreadonlystring-repo/repo.ts:139
priorityReporeadonlyboolean-repo/repo.ts:112
storagereadonlyST-repo/repo.ts:113
trustPoolreadonlyTrustPool-repo/repo.ts:114

Accessors

isActive

Get Signature

get isActive(): boolean

Defined in: base/emitter.ts:57

Returns

boolean

Inherited from

Emitter.isActive


orgId

Get Signature

get orgId(): string

Defined in: repo/repo.ts:201

Returns

string

Methods

attach()

attach<C, E>(e, c): () => void

Defined in: base/emitter.ts:116

Type Parameters

Type Parameter
C extends Function
E extends RepositoryEvent | EmitterEvent

Parameters

ParameterType
eE
cC

Returns

() => void

Inherited from

Emitter.attach


changedFieldsInCommit()

changedFieldsInCommit(commit): string[]

Defined in: repo/repo.ts:328

This method computes a quick diff between the given commit and all of its parents. It determines which fields were changed in this commit, rather than what the changes were.

Parameters

ParameterTypeDescription
commitstring | CommitThe commit to inspect.

Returns

string[]

An array of fields changed in this commit or null if the full information isn't yet available for this commit due to partial commit graph.


commitIsCorrupted()

commitIsCorrupted(c): boolean

Defined in: repo/repo.ts:640

Parameters

ParameterType
cCommit

Returns

boolean


commitIsLeaf()

commitIsLeaf(candidate): boolean

Defined in: repo/repo.ts:364

Returns true if the given commit is a leaf in the commit graph, meaning no other commit references it — either as a direct parent or as an explicit ancestor — i.e. it has no in-edges of any kind in the adjacency list.

Note: persistVerifiedCommits registers both parent and ancestor edges, so a commit that appears only in another commit's ancestors array is also not a leaf. This prevents a merge from re-including commits that are already transitively covered by a descendant.

Parameters

ParameterTypeDescription
candidatestring | CommitThe commit to inspect.

Returns

boolean

true if the commit is a leaf and can be safely included in a merge commit, false otherwise.


commits()

commits(session?): Generator<Commit>

Defined in: repo/repo.ts:251

Parameters

ParameterType
session?Session

Returns

Generator<Commit>


commitsForKey()

commitsForKey(key, session?): Generator<Commit>

Defined in: repo/repo.ts:283

Parameters

ParameterType
keystring
session?Session

Returns

Generator<Commit>


create()

create<S>(key, value): Promise<Commit>

Defined in: repo/repo.ts:1208

Type Parameters

Type Parameter
S extends Schema

Parameters

ParameterType
keystring
valueItem<S>

Returns

Promise<Commit>


debugNetworkForKey()

debugNetworkForKey(key): ReadonlyJSONObject

Defined in: repo/repo.ts:1631

Parameters

ParameterType
keystring

Returns

ReadonlyJSONObject


detach()

detach<C, E>(e, c): void

Defined in: base/emitter.ts:149

Type Parameters

Type Parameter
C extends Function
E extends RepositoryEvent | EmitterEvent

Parameters

ParameterType
eE
cC

Returns

void

Inherited from

Emitter.detach


detachAll()

detachAll<E>(e?): void

Defined in: base/emitter.ts:188

Type Parameters

Type Parameter
E extends RepositoryEvent | EmitterEvent

Parameters

ParameterType
e?E

Returns

void

Inherited from

Emitter.detachAll


downloadDebugNetworkForKey()

downloadDebugNetworkForKey(key): void

Defined in: repo/repo.ts:1687

Parameters

ParameterType
keystring

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 RepositoryEvent | EmitterEvent

Parameters

ParameterType
eE
a0?unknown
a1?unknown

Returns

void

Inherited from

Emitter.emit


findLatestAncestorFromCommit()

findLatestAncestorFromCommit(commit, filter): Commit

Defined in: repo/repo.ts:1712

Parameters

ParameterType
commitstring | Commit
filter(c) => boolean

Returns

Commit


findLatestNonCorruptedCommitForKey()

findLatestNonCorruptedCommitForKey(key): Commit

Defined in: repo/repo.ts:690

Parameters

ParameterType
keystring

Returns

Commit


findMergeBase()

findMergeBase(commits): [Commit[], Commit, Schema, boolean]

Defined in: repo/repo.ts:434

Given an iterable of commits, this method returns their Lowest Common Ancestor or undefined if no such ancestor exists (meaning the commits belong to disconnected histories).

Parameters

ParameterTypeDescription
commitsCommit[]An iterable of commits.

Returns

[Commit[], Commit, Schema, boolean]

A tuple of 4 values:

  1. The commits to include in the merge. Commits with broken ancestry path or deferred merges are excluded.

  2. The base commit (LCA) to use for the merge, or undefined if one can't be found.

  3. The scheme to use for the merge.

  4. Whether a root commit was encountered during traversal.


findNonCorruptedParentsFromCommits()

findNonCorruptedParentsFromCommits(parents): Commit[]

Defined in: repo/repo.ts:665

Parameters

ParameterType
parents(string | Commit)[]

Returns

Commit[]


getCommit()

getCommit(id, session?): Commit

Defined in: repo/repo.ts:222

Parameters

ParameterType
idstring
session?Session

Returns

Commit


graphForKey()

graphForKey(key): CommitGraph[]

Defined in: repo/repo.ts:1602

Parameters

ParameterType
keystring

Returns

CommitGraph[]


hasCommit()

hasCommit(id): boolean

Defined in: repo/repo.ts:245

Parameters

ParameterType
idstring

Returns

boolean


hasItemForCommit()

hasItemForCommit(c): boolean

Defined in: repo/repo.ts:614

Parameters

ParameterType
cstring | Commit

Returns

boolean


hasKey()

hasKey(key): boolean

Defined in: repo/repo.ts:1384

Parameters

ParameterType
keystring

Returns

boolean


headForKey()

headForKey(key): Commit

Defined in: repo/repo.ts:797

This method finds and returns the head for the given key. This is a readonly operation and does not attempt to merge any leaves.

Parameters

ParameterTypeDescription
keystringThe key to search for.

Returns

Commit

The head commit, or undefined if no commit can be found for this key. Note that while this method may return undefined, some commits may still be present for this key. This happens when these commits are delta commits, and their base isn't present thus rendering them unreadable.


insert()

insert(entries): Promise<Commit[]>

Defined in: repo/repo.ts:1217

Bulk-insert new items into this repository. Items whose keys already exist fall back to the per-item setValueForKey path; new keys are batched for significantly lower overhead.

Parameters

ParameterType
entriesobject[]

Returns

Promise<Commit[]>


itemForCommit()

itemForCommit<S>(c): Item<S>

Defined in: repo/repo.ts:700

Type Parameters

Type Parameter
S extends Schema

Parameters

ParameterType
cstring | Commit

Returns

Item<S>


keyExists()

keyExists(key): boolean

Defined in: repo/repo.ts:311

Parameters

ParameterType
keystring

Returns

boolean


keys()

keys(session?): Iterable<string>

Defined in: repo/repo.ts:387

Parameters

ParameterType
session?Session

Returns

Iterable<string>


leavesForKey()

leavesForKey(key): readonly Commit[]

Defined in: repo/repo.ts:372

Parameters

ParameterType
keystring

Returns

readonly Commit[]


mergeIfNeeded()

mergeIfNeeded(key): Promise<Commit>

Defined in: repo/repo.ts:1049

Parameters

ParameterType
keystring

Returns

Promise<Commit>


mute()

mute(): void

Defined in: base/emitter.ts:288

Returns

void

Inherited from

Emitter.mute


numberOfCommits()

numberOfCommits(session?): number

Defined in: repo/repo.ts:205

Parameters

ParameterType
session?Session

Returns

number


once()

once<C, E>(e, c): () => void

Defined in: base/emitter.ts:248

Type Parameters

Type Parameter
C extends Function
E extends RepositoryEvent | EmitterEvent

Parameters

ParameterType
eE
cC

Returns

() => void

Inherited from

Emitter.once


paths()

paths(session?): Iterable<string>

Defined in: repo/repo.ts:409

Parameters

ParameterType
session?Session

Returns

Iterable<string>


persistCommits()

persistCommits(commits): Promise<Commit[]>

Defined in: repo/repo.ts:1467

Parameters

ParameterType
commitsIterable<Commit>

Returns

Promise<Commit[]>


persistVerifiedCommits()

persistVerifiedCommits(commits): Promise<Commit[]>

Defined in: repo/repo.ts:1502

Parameters

ParameterType
commitsIterable<Commit>

Returns

Promise<Commit[]>


rebase()

rebase<S>(key, record, headId): [Item<S>, string]

Defined in: repo/repo.ts:1282

Given a key and an edited record for this key, this method rebases the changes from the record on top of the any changes made concurrently for this key. Use it to merge remote changes with any local edits before committing them.

Type Parameters

Type Parameter
S extends Schema

Parameters

ParameterTypeDescription
keystringThe key to rebase.
recordItem<S>The locally edited record.
headIdstring | CommitThe commit from which the edited record was derived from.

Returns

[Item<S>, string]

A new record with local changes rebased on top of remote changes. This record can be used to safely update the UI, as well as update the repo value.


resume()

protected resume(): void

Defined in: base/emitter.ts:286

Returns

void

Inherited from

Emitter.resume


revertAllKeysToBefore()

revertAllKeysToBefore(ts): void

Defined in: repo/repo.ts:1694

Parameters

ParameterType
tsnumber

Returns

void


revertHeadsByConnectionId()

revertHeadsByConnectionId(connectionIds): void

Defined in: repo/repo.ts:1734

Parameters

ParameterType
connectionIdsstring | string[]

Returns

void


setValueForKey()

setValueForKey<S>(key, value, parentCommit): Promise<Commit>

Defined in: repo/repo.ts:1131

Updates the head record for a given key.

Type Parameters

Type Parameter
S extends Schema

Parameters

ParameterTypeDescription
keystringThe key who's head to update.
valueItem<S>The value to write.
parentCommitstring | Commit-

Returns

Promise<Commit>

Whether or not a new commit had been generated. Regardless of the returned value, future calls to valueForKey will return the updated record.


suspend()

protected suspend(): void

Defined in: base/emitter.ts:284

Returns

void

Inherited from

Emitter.suspend


unmute()

unmute(): void

Defined in: base/emitter.ts:292

Returns

void

Inherited from

Emitter.unmute


valueForKey()

valueForKey<T>(key): [Item<T>, Commit]

Defined in: repo/repo.ts:1107

Type Parameters

Type ParameterDefault type
T extends SchemaSchema

Parameters

ParameterType
keystring

Returns

[Item<T>, Commit]


verifyCommits()

verifyCommits(commits): Promise<Commit[]>

Defined in: repo/repo.ts:1391

Parameters

ParameterType
commitsIterable<Commit>

Returns

Promise<Commit[]>


normalizePath()

static normalizePath(id): string

Defined in: repo/repo.ts:191

Parameters

ParameterType
idstring

Returns

string


parseId()

static parseId(id): [string, string]

Defined in: repo/repo.ts:182

Parameters

ParameterType
idstring

Returns

[string, string]


path()

static path(storage, id): string

Defined in: repo/repo.ts:178

Parameters

ParameterType
storagestring
idstring

Returns

string