OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git-v3 / lib / services / migrate / linearize.js

15 lines · javascript ref:
/**
 * Linearize an autobase view to its latest state before a read. The right
 * call depends on the wrapper:
 *   - HyperIssues / HyperOrgs expose `.sync()` (their `.update(...)` is a
 *     DOMAIN method — issue-update / org-update — and must NOT be called here);
 *   - a hyper-rooms Room exposes the autobase as `.base` (→ base.base.update);
 *   - a raw Autobase has `.update()`.
 * Tried in that order. Read-only: never appends.
 */
export async function linearize (base) {
  if (typeof base.sync === 'function') return base.sync()
  if (base.base && typeof base.base.update === 'function') return base.base.update()
  if (typeof base.update === 'function') return base.update()
}