Class: Repository<ST>
Defined in: repo/repo.ts:110
Extends
Emitter<RepositoryEvent>
Type Parameters
| Type Parameter | Default type |
|---|---|
ST extends RepoStorage<ST> | MemRepoStorage |
Constructors
Constructor
new Repository<
ST>(db,path,trustPool,__namedParameters?):Repository<ST>
Defined in: repo/repo.ts:150
Parameters
| Parameter | Type |
|---|---|
db | GoatDB |
path | string |
trustPool | TrustPool |
__namedParameters | RepositoryConfig<ST> |
Returns
Repository<ST>
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
allowedNamespaces | readonly | string[] | - | repo/repo.ts:116 |
alwaysActive | readonly | boolean | Emitter.alwaysActive | base/emitter.ts:10 |
authorizer? | readonly | AuthRule | - | repo/repo.ts:118 |
db | readonly | GoatDB | - | repo/repo.ts:151 |
path | readonly | string | - | repo/repo.ts:152 |
priorityRepo | readonly | boolean | - | repo/repo.ts:113 |
storage | readonly | ST | - | repo/repo.ts:114 |
trustPool | readonly | TrustPool | - | repo/repo.ts:115 |
Accessors
isActive
Get Signature
get isActive():
boolean
Defined in: base/emitter.ts:63
Returns
boolean
Inherited from
orgId
Get Signature
get orgId():
string
Defined in: repo/repo.ts:327
Returns
string
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
| Parameter | Type |
|---|---|
event | string |
Returns
void
Inherited from
attach()
attach<
C,E>(e,c): () =>void
Defined in: base/emitter.ts:139
Type Parameters
| Type Parameter |
|---|
C extends Function |
E extends RepositoryEvent | EmitterEvent |
Parameters
| Parameter | Type |
|---|---|
e | E |
c | C |
Returns
() => void
Inherited from
changedFieldsInCommit()
changedFieldsInCommit(
commit):string[]
Defined in: repo/repo.ts:456
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
| Parameter | Type | Description |
|---|---|---|
commit | string | Commit | The 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:770
Parameters
| Parameter | Type |
|---|---|
c | Commit |
Returns
boolean
commitIsLeaf()
commitIsLeaf(
candidate):boolean
Defined in: repo/repo.ts:492
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
| Parameter | Type | Description |
|---|---|---|
candidate | string | Commit | The 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:378
Parameters
| Parameter | Type |
|---|---|
session? | Session |
Returns
Generator<Commit>
commitsForKey()
commitsForKey(
key,session?):Generator<Commit>
Defined in: repo/repo.ts:410
Parameters
| Parameter | Type |
|---|---|
key | string |
session? | Session |
Returns
Generator<Commit>
create()
create<
S>(key,value):Promise<Commit>
Defined in: repo/repo.ts:1363
Type Parameters
| Type Parameter |
|---|
S extends Schema |
Parameters
| Parameter | Type |
|---|---|
key | string |
value | Item<S> |
Returns
Promise<Commit>
debugNetworkForKey()
debugNetworkForKey(
key):ReadonlyJSONObject
Defined in: repo/repo.ts:1805
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
detach()
detach<
C,E>(e,c):void
Defined in: base/emitter.ts:173
Type Parameters
| Type Parameter |
|---|
C extends Function |
E extends RepositoryEvent | EmitterEvent |
Parameters
| Parameter | Type |
|---|---|
e | E |
c | C |
Returns
void
Inherited from
detachAll()
detachAll<
E>(e?):void
Defined in: base/emitter.ts:214
Type Parameters
| Type Parameter |
|---|
E extends RepositoryEvent | EmitterEvent |
Parameters
| Parameter | Type |
|---|---|
e? | E |
Returns
void
Inherited from
downloadDebugNetworkForKey()
downloadDebugNetworkForKey(
key):void
Defined in: repo/repo.ts:1861
Parameters
| Parameter | Type |
|---|---|
key | string |
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 RepositoryEvent | EmitterEvent |
Parameters
| Parameter | Type |
|---|---|
e | E |
a0? | unknown |
a1? | unknown |
Returns
void
Inherited from
findLatestAncestorFromCommit()
findLatestAncestorFromCommit(
commit,filter):Commit
Defined in: repo/repo.ts:1886
Parameters
| Parameter | Type |
|---|---|
commit | string | Commit |
filter | (c) => boolean |
Returns
Commit
findLatestNonCorruptedCommitForKey()
findLatestNonCorruptedCommitForKey(
key):Commit
Defined in: repo/repo.ts:820
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Commit
findMergeBase()
findMergeBase(
commits): [Commit[],Commit,Schema,boolean]
Defined in: repo/repo.ts:564
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
| Parameter | Type | Description |
|---|---|---|
commits | Commit[] | An iterable of commits. |
Returns
[Commit[], Commit, Schema, boolean]
A tuple of 4 values:
-
The commits to include in the merge. Commits with broken ancestry path or deferred merges are excluded.
-
The base commit (LCA) to use for the merge, or undefined if one can't be found.
-
The scheme to use for the merge.
-
Whether a root commit was encountered during traversal.
findNonCorruptedParentsFromCommits()
findNonCorruptedParentsFromCommits(
parents):Commit[]
Defined in: repo/repo.ts:795
Parameters
| Parameter | Type |
|---|---|
parents | (string | Commit)[] |
Returns
Commit[]
getCommit()
getCommit(
id,session?):Commit
Defined in: repo/repo.ts:348
Parameters
| Parameter | Type |
|---|---|
id | string |
session? | Session |
Returns
Commit
graphForKey()
graphForKey(
key):CommitGraph[]
Defined in: repo/repo.ts:1776
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
CommitGraph[]
hasCommit()
hasCommit(
id):boolean
Defined in: repo/repo.ts:372
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
boolean
hasItemForCommit()
hasItemForCommit(
c):boolean
Defined in: repo/repo.ts:744
Parameters
| Parameter | Type |
|---|---|
c | string | Commit |
Returns
boolean
hasKey()
hasKey(
key):boolean
Defined in: repo/repo.ts:1558
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
boolean
headForKey()
headForKey(
key):Commit
Defined in: repo/repo.ts:927
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
| Parameter | Type | Description |
|---|---|---|
key | string | The 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:1372
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
| Parameter | Type |
|---|---|
entries | object[] |
Returns
Promise<Commit[]>
itemForCommit()
itemForCommit<
S>(c):Item<S>
Defined in: repo/repo.ts:830
Type Parameters
| Type Parameter |
|---|
S extends Schema |
Parameters
| Parameter | Type |
|---|---|
c | string | Commit |
Returns
Item<S>
keyExists()
keyExists(
key):boolean
Defined in: repo/repo.ts:438
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
boolean
keys()
keys(
session?):Iterable<string>
Defined in: repo/repo.ts:515
Parameters
| Parameter | Type |
|---|---|
session? | Session |
Returns
Iterable<string>
leavesForKey()
leavesForKey(
key): readonlyCommit[]
Defined in: repo/repo.ts:500
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
readonly Commit[]
mergeIfNeeded()
mergeIfNeeded(
key):Promise<Commit>
Defined in: repo/repo.ts:1180
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<Commit>
mute()
mute():
void
Defined in: base/emitter.ts:344
Returns
void
Inherited from
numberOfCommits()
numberOfCommits(
session?):number
Defined in: repo/repo.ts:331
Parameters
| Parameter | Type |
|---|---|
session? | Session |
Returns
number
once()
once<
C,E>(e,c): () =>void
Defined in: base/emitter.ts:278
Type Parameters
| Type Parameter |
|---|
C extends Function |
E extends RepositoryEvent | EmitterEvent |
Parameters
| Parameter | Type |
|---|---|
e | E |
c | C |
Returns
() => void
Inherited from
paths()
paths(
session?):Iterable<string>
Defined in: repo/repo.ts:538
Parameters
| Parameter | Type |
|---|---|
session? | Session |
Returns
Iterable<string>
persistCommits()
persistCommits(
commits):Promise<Commit[]>
Defined in: repo/repo.ts:1641
Parameters
| Parameter | Type |
|---|---|
commits | Iterable<Commit> |
Returns
Promise<Commit[]>
persistVerifiedCommits()
persistVerifiedCommits(
commits):Promise<Commit[]>
Defined in: repo/repo.ts:1676
Parameters
| Parameter | Type |
|---|---|
commits | Iterable<Commit> |
Returns
Promise<Commit[]>
rebase()
rebase<
S>(key,record,headId): [Item<S>,string]
Defined in: repo/repo.ts:1456
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
| Parameter | Type | Description |
|---|---|---|
key | string | The key to rebase. |
record | Item<S> | The locally edited record. |
headId | string | Commit | The 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()
protectedresume():void
Defined in: base/emitter.ts:342
Returns
void
Inherited from
revertAllKeysToBefore()
revertAllKeysToBefore(
ts):void
Defined in: repo/repo.ts:1868
Parameters
| Parameter | Type |
|---|---|
ts | number |
Returns
void
revertHeadsByConnectionId()
revertHeadsByConnectionId(
connectionIds):void
Defined in: repo/repo.ts:1908
Parameters
| Parameter | Type |
|---|---|
connectionIds | string | string[] |
Returns
void
setValueForKey()
setValueForKey<
S>(key,value,parentCommit):Promise<Commit>
Defined in: repo/repo.ts:1263
Updates the head record for a given key.
Type Parameters
| Type Parameter |
|---|
S extends Schema |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key who's head to update. |
value | Item<S> | The value to write. |
parentCommit | string | 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()
protectedsuspend():void
Defined in: base/emitter.ts:340
Returns
void
Inherited from
unmute()
unmute():
void
Defined in: base/emitter.ts:348
Returns
void
Inherited from
valueForKey()
valueForKey<
T>(key): [Item<T>,Commit]
Defined in: repo/repo.ts:1238
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends Schema | Schema |
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
[Item<T>, Commit]
verifyCommits()
verifyCommits(
commits):Promise<Commit[]>
Defined in: repo/repo.ts:1565
Parameters
| Parameter | Type |
|---|---|
commits | Iterable<Commit> |
Returns
Promise<Commit[]>
isSystemRepo()
staticisSystemRepo(path):boolean
Defined in: repo/repo.ts:234
True when the given repository path belongs to the system namespace
(/sys or /sys/*). System repositories are exempt from inactivity
auto-close.
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
boolean
normalizePath()
staticnormalizePath(id):string
Defined in: repo/repo.ts:219
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
string
parseId()
staticparseId(id): [string,string]
Defined in: repo/repo.ts:210
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
[string, string]
path()
staticpath(storage,id):string
Defined in: repo/repo.ts:206
Parameters
| Parameter | Type |
|---|---|
storage | string |
id | string |
Returns
string
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
| Parameter | Type |
|---|---|
event | RepositoryEvent | EmitterEvent |
Returns
number