Constructor
new VersionTracker()
- Since:
- Source:
Examples
const vt = new VersionTracker({
metaServiceUrl: "https://example.com/sysmeta",
})
vt.getNth("pid123", 1).then((result) => {
console.log("Next version PID:", result.pid);
});
const fullChain = await vt.getFullChain("pid123");
console.log("All versions in chain:", fullChain.prev, fullChain.next);
// Get a singleton instance for a specific SysMeta service URL
// This will create a new instance if it doesn't exist yet.
const vt = VersionTracker.get("https://example.com/sysmeta");
Methods
addVersion(prevPid, newPid, sysMetaopt)
Manually register that `newPid` obsoletes (comes after) `prevPid`. Useful
when an external editor just created a brand‑new revision so the chain
can be updated immediately without refetching SysMeta. If `sysMeta` for
the new PID is already available, pass it to avoid a network round‑trip;
otherwise the tracker will fetch it lazily when first requested.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
prevPid |
string
|
|
|
the PID of the previous version |
newPid |
string
|
|
|
the PID of the new version |
sysMeta |
SysMeta
|
<optional>
|
null
|
optional SysMeta object for the new version. |
- Source:
clear() → {Promise.<boolean>}
Clear the entire cache, including in-memory and persistent store.
- Source:
Returns:
- resolves to true if the cache was cleared
-
Type
-
Promise.<boolean>
getAdjacent(pid, ignoreEndopt, withMetaopt) → {Promise.<{pid: string, prev: VersionResult, next:VersionResult}>}
Get the version before and after the given PID, if available.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
pid |
string
|
|
|
the PID to get adjacent versions for |
ignoreEnd |
boolean
|
<optional>
|
false
|
If true, ignore end flags and continue
walking the chain even if it appears complete. |
withMeta |
boolean
|
<optional>
|
false
|
If true, the SysMeta will be fetched if not
already available in the cache. |
- Since:
- Source:
Returns:
- resolves to an object with `pid`, `prev`, and `next` properties. `prev`
and `next` are either PIDs or objects with { pid, sysMeta } if
`withMeta` is true. If no previous or next version is found, the
respective property will be null.
-
Type
-
Promise.<{pid: string, prev: VersionResult, next:VersionResult}>
getFullChain(pid, ignoreEndopt, withMetaopt) → {Promise.<VersionRecord>}
Get the complete version chain for the given PID.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
pid |
string
|
|
|
PID to get the chain for |
ignoreEnd |
boolean
|
<optional>
|
false
|
Re‑probe past cached end flags |
withMeta |
boolean
|
<optional>
|
false
|
If true, return arrays of { pid, sysMeta }
instead of bare PIDs. |
- Source:
Returns:
- resolves to an object with `prev`,
`next`, `sysMeta`, `endPrev`, and `endNext` properties.
-
Type
-
Promise.<VersionRecord>
getLatestVersion(pid, ignoreEndopt, withMetaopt) → {Promise.<(string|VersionResult)>}
Get the latest version PID in the version chain for the given PID.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
pid |
string
|
|
|
the PID to get the latest version for |
ignoreEnd |
boolean
|
<optional>
|
false
|
If true, ignore end flags and continue
walking the chain even if it appears complete. This is useful for
re-checking if a newer version exists. |
withMeta |
boolean
|
<optional>
|
false
|
If true, the SysMeta will be fetched if not
already available in the cache. |
- Source:
Returns:
- resolves to the latest PID in
the chain, or an object with { pid, sysMeta } if `withMeta` is true. If
no versions are found, resolves to the original PID.
-
Type
-
Promise.<(string|VersionResult)>
getNext(pid, ignoreEndopt, withMetaopt) → {Promise.<VersionResult>}
Get the next most recent version after the given PID.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
pid |
string
|
|
|
the PID to get the next version for |
ignoreEnd |
boolean
|
<optional>
|
false
|
If true, ignore end flags and continue
walking the chain even if it appears complete. |
withMeta |
boolean
|
<optional>
|
false
|
If true, the SysMeta will be fetched if not
already available in the cache. |
- Since:
- Source:
Returns:
- resolves to the next version PID or
an object with { pid, sysMeta } if `withMeta` is true. If no next version
is found, resolves to the original PID.
-
Type
-
Promise.<VersionResult>
getNth(pid, offset, ignoreEndopt, withMetaopt) → {Promise.<(VersionResult|string|null)>}
Get the PID that is `offset` earlier or later in the version chain
relative to the given `pid`.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
pid |
string
|
|
|
the PID to start from |
offset |
number
|
|
|
the number of steps to move in the chain. 0 =
same PID, +n newer, -n older |
ignoreEnd |
boolean
|
<optional>
|
false
|
Set to true to allow walking beyond cached
chain end (e.g. to re-check whether there's a newer version) |
withMeta |
boolean
|
<optional>
|
false
|
If true, return arrays of { pid, sysMeta }
instead of bare PIDs. |
- Source:
Returns:
- resolves to the requested
PID at the given offset, or null if no such version exists. If `withMeta`
is true, resolves to an object with { pid, sysMeta }.
-
Type
-
Promise.<(VersionResult|string|null)>
getPrev(pid, ignoreEndopt, withMetaopt) → {Promise.<VersionResult>}
Get the previous version before the given PID.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
pid |
string
|
|
|
the PID to get the previous version for |
ignoreEnd |
boolean
|
<optional>
|
false
|
If true, ignore end flags and continue
walking the chain even if it appears complete. |
withMeta |
boolean
|
<optional>
|
false
|
If true, the SysMeta will be fetched if not
already available in the cache. |
- Since:
- Source:
Returns:
- resolves to the previous version PID
or an object with { pid, sysMeta } if `withMeta` is true. If no previous
version is found, resolves to the original PID.
-
Type
-
Promise.<VersionResult>
refresh(pid) → {Promise.<object>}
Refresh the version chain for the given PID by removing it from the cache
and re-fetching the full chain from the SysMeta service.
Parameters:
Name |
Type |
Description |
pid |
string
|
the PID to refresh |
- Source:
Returns:
- resolves to the refreshed chain object
-
Type
-
Promise.<object>
setTTL(ms)
Set the Time-To-Live (TTL) for cached records.
Parameters:
Name |
Type |
Description |
ms |
number
|
the TTL in milliseconds |
- Source:
getToken() → {Promise.<string>}
Ensure the user is authenticated and has a valid token.
- Source:
Returns:
- resolves to the user's token
-
Type
-
Promise.<string>