@dxos/echo
    Preparing search index...

    Interface Database

    ECHO Database interface.

    interface Database {
        "[TypeId]": typeof Database.TypeId;
        query: QueryFn;
        registry: Registry.Registry;
        get graph(): Hypergraph.Hypergraph;
        get spaceId(): Key.SpaceId;
        add<T extends Entity.Unknown = Entity.Unknown>(
            obj: T & RejectTypeEntity<T>,
            opts?: AddOptions,
        ): T;
        addType<T extends AnyEntity>(type: T, opts?: WriteOptions): Promise<T>;
        appendToFeed(
            feed: Feed.Feed,
            entities: Entity.Unknown[],
            opts?: WriteOptions,
        ): Promise<void>;
        beginMigration(options?: TransactionOptions): Promise<Transaction>;
        blobExists(blob: Blob.Blob): Promise<boolean>;
        branch<T extends Obj.Unknown>(
            obj: T,
            name: string,
        ): Promise<BranchBinding<T>>;
        createBlob(
            bytes: Uint8Array,
            options?: { storage?: string; type?: string },
        ): Promise<Blob.Blob>;
        createBlobFromUpload(
            uploadId: string,
            options?: { storage?: string },
        ): Promise<Blob.Blob>;
        createBranch(
            rootObjectId: string,
            name: string,
            opts?: {
                fromHeads?: readonly string[] | Record<string, readonly string[]>;
            },
        ): Promise<void>;
        deleteBranch(rootObjectId: string, name: string): void;
        deleteFromFeed(feed: Feed.Feed, entities: Entity.Unknown[]): Promise<void>;
        evictFeedHandle(feed: Feed.Feed): Promise<void>;
        flush(opts?: FlushOptions): Promise<void>;
        forkFeed(
            feed: Feed.Feed,
            base: Entity.Unknown,
            opts: { at: string | Entity.Unknown | Entity.Snapshot },
        ): Promise<string & Brand<"@dxos/echo/Feed/BranchId">>;
        getBlobUrl(blob: Blob.Blob): Promise<undefined | string>;
        getChanges<T extends Obj.Unknown>(
            obj: T,
            opts?: GetChangesOptions<string>,
        ): ValueChange<unknown>[];
        getCurrentBranch(objectId: string): string;
        getFeedSyncState(feed: Feed.Feed): Promise<Feed.SyncState>;
        getObjectById<T extends Obj.Unknown = Obj.OfShape<AnyProperties>>(
            id: string,
            opts?: GetObjectByIdOptions,
        ): undefined | T;
        getSyncState(options?: GetSyncStateOptions): Promise<Database.SyncState>;
        getVersion<T extends Obj.Unknown>(
            obj: T,
            heads: readonly string[],
        ): Obj.Snapshot<T>;
        listBranches(objectId: string): string[];
        makeRef<T extends Entity.Unknown = Entity.Unknown>(uri: URI.URI): Ref<T>;
        mergeBranch(
            rootObjectId: string,
            name: string,
            opts?: { deleteAfter?: boolean },
        ): Promise<void>;
        readBlob(blob: Blob.Blob): Promise<Uint8Array<ArrayBufferLike>>;
        remove(obj: Entity.Unknown, opts?: WriteOptions): void;
        removeFeedItemsByIds(
            feed: Feed.Feed,
            ids: string[],
            options?: { branches?: readonly (null | string)[] },
        ): Promise<void>;
        retainObjects(keep: Iterable<string>): string[];
        runGarbageCollection(
            options?: GarbageCollectionOptions,
        ): Promise<GarbageCollectionReport>;
        stats(): Promise<DatabaseStats>;
        subscribeToSyncState(
            cb: (state: Database.SyncState) => void,
            options?: GetSyncStateOptions,
        ): CleanupFn;
        switchBranch(rootObjectId: string, name: string): Promise<void>;
        syncBranch(rootObjectId: string, name: string): Promise<void>;
        syncFeed(feed: Feed.Feed, options?: SyncOptions): Promise<void>;
        toJSON(): object;
    }

    Hierarchy (View Summary)

    Index

    Properties

    "[TypeId]": typeof Database.TypeId
    query: QueryFn

    Query objects.

    O(AST size) to key the result cache; returns a shared, lazily executed result, so nothing runs until read.

    registry: Registry.Registry

    Registry for this database. Delegates type lookups to the shared hypergraph registry. To persist a schema so it replicates to other clients, add the type entity with addType (e.g. await db.addType(Type.makeObjectFromJsonSchema(...))).

    Accessors

    Methods

    • Persists a Type definition (clones/forks the entity) so it replicates to other peers.

      Runs a conflict query first: if a type with the same typename + version already exists in this space, the existing persisted entity is returned and no duplicate is created. This is the only supported way to add Type entities — add rejects them.

      Type Parameters

      Parameters

      Returns Promise<T>

      Async; O(t) in the space persisted types, which it queries in full for a duplicate before writing.

    • Create a caller-owned, writable binding to one branch of one object — a live object whose reads resolve the branch document and whose writes land on the branch document only. Multiple bindings to different branches of the same object may coexist; the device-global current branch and other bindings are unaffected. Binding to 'main' returns the canonical live object. Bindings are ephemeral and never persisted — the caller must dispose().

      Type Parameters

      Parameters

      • obj: T
      • name: string

      Returns Promise<BranchBinding<T>>

      Async; O(1) for main, otherwise loads and binds the branch document of this one object.

    • Hashes and uploads bytes via the chosen storage backend, returning an un-added Blob object. Rejects with Error.BlobTooLargeError (over inline storage's fixed cap, or the backend's own maxSize), Error.BlobWriteError (backend upload failure), or Error.BlobNotAvailableError (reason: 'backend-not-registered' — the requested storage name has no registered backend).

      Parameters

      • bytes: Uint8Array
      • Optionaloptions: { storage?: string; type?: string }

      Returns Promise<Blob.Blob>

      Async; O(size) to hash, plus the backend upload (a no-op for inline storage).

    • Adopts bytes already staged by a direct upload, returning an un-added Blob object.

      Unlike createBlob the bytes never enter this process: they were written straight to the store by whoever held the upload URL, which is the point — the uploader is typically an agent's shell moving a file far too large to pass through a model. Size and content type therefore come back from the store rather than from the caller.

      Rejects with Error.BlobNotAvailableError (reason: 'backend-not-registered' when the storage name has no backend, 'not-found' when the backend cannot adopt uploads or the upload is gone) or Error.BlobWriteError if adoption fails.

      Parameters

      • uploadId: string
      • Optionaloptions: { storage?: string }

      Returns Promise<Blob.Blob>

      Async; one backend round trip, and the bytes never pass through this process.

    • Fork the object and its referenced subtree into a new branch (does not switch to it).

      Parameters

      • rootObjectId: string
      • name: string
      • Optionalopts: { fromHeads?: readonly string[] | Record<string, readonly string[]> }
        • OptionalfromHeads?: readonly string[] | Record<string, readonly string[]>

          Fork from a historical frontier instead of the tip (a bare heads array applies to the root only; a map forks each member from its own frontier).

      Returns Promise<void>

      Async; O(subtree size), each member document forked as a full history copy.

    • Delete a branch (its documents lose their sync reference). Cannot delete 'main'.

      Parameters

      • rootObjectId: string
      • name: string

      Returns void

      O(subtree size); one root-document change plus a background rebind of members viewing the branch.

    • Disposes and drops the in-memory handle (live working-set / core cache) for a feed, so the next access re-reads it cold. Advanced cache-control; primarily used by tests to model a spawned process reading the feed with an empty in-memory cache. Public (not _-prefixed) so it survives declaration stripping for cross-package test use.

      Parameters

      Returns Promise<void>

      Async; O(1) eviction, and the next access re-reads the feed cold.

    • Wait for all pending changes to be saved to disk. Optionaly waits for changes to be propagated to indexes and event handlers.

      Parameters

      Returns Promise<void>

      Async; always waits for pending document creation, then only for the disk, index and update work that opts selects, so it is as slow as that selected backlog.

    • Returns a renderable URL for the blob, if one can be produced.

      Parameters

      Returns Promise<undefined | string>

      Async; an inline blob encodes all of its bytes into a data: URL (O(size)), an external one asks the backend.

    • The device-global current branch for an object id ('main' by default).

      Parameters

      • objectId: string

      Returns string

      Prefer Obj.getBranch(obj) — it takes the object and reports the branch of that specific instance (including db.branch() independent instances), not just the device selection.

      O(1) device-local map lookup.

    • An immutable snapshot of the object at the given historical heads — a detached instance, not a pin on the live object. Prefer Obj.getVersion(obj, heads).

      Type Parameters

      Parameters

      • obj: T
      • heads: readonly string[]

      Returns Obj.Snapshot<T>

      O(object size) plus the Automerge cost of viewing the document at heads; nothing is cached.

    • All branch names available for an object, including the implicit 'main' (always first).

      Parameters

      • objectId: string

      Returns string[]

      O(1) for a subtree root; a member scans every branch record in the space to find its root.

    • Creates a reference to an existing object in the database.

      NOTE: The reference may be dangling if the object is not present in the database. NOTE: Difference from Ref.fromURI Ref.fromURI(dxn) returns an unhydrated reference. The .load and .target APIs will not work. db.makeRef(dxn) is preferable in cases with access to the database.

      Type Parameters

      Parameters

      Returns Ref<T>

      O(1); allocates a resolver-bound ref without looking the target up.

    • Merge a branch back into main across the subtree, then switch back to main.

      Parameters

      • rootObjectId: string
      • name: string
      • Optionalopts: { deleteAfter?: boolean }

      Returns Promise<void>

      Async; O(subtree size) Automerge merges followed by a switch back to main.

    • Loads a blob's bytes. Rejects with Error.BlobNotAvailableError if the backend for the blob's storage scheme is not registered, offline, or cannot find the bytes.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Async; O(size), read inline or fetched from the backend.

    • Removes feed items by ID. branches names the branch of each item by index (null for the root), for an item this client holds no live copy of; without it such an item is removed from the root branch.

      Parameters

      • feed: Feed.Feed
      • ids: string[]
      • Optionaloptions: { branches?: readonly (null | string)[] }

      Returns Promise<void>

      Async; O(n) in ids, deleted in one batch.

    • Replaces the set of objects the space directory tracks, dropping everything not retained.

      Derived from the directory's own maps, so clearing a space costs one change rather than a scan of its contents. The objects are dropped, not soft-deleted: they are gone from the space and their documents are reclaimed by garbage collection, on this peer and — as the change replicates — on every other. Permanent; there is nothing left to restore from.

      Parameters

      • keep: Iterable<string>

      Returns string[]

      Ids of the objects dropped from the directory.

      O(directory size) scan of the space root plus one root-document change, with no object loads.

    • Per-space storage metrics: objects (alive/deleted), automerge documents, feeds, feed blocks. Read-only. Intended as an occasional/administrative call. See garbage-collection design notes in @dxos/echo-host.

      Returns Promise<DatabaseStats>

      Async; one host round trip plus an O(feeds) client-side tally.

    • Switch the object's subtree to a branch (or back to 'main'). Device-local; cascades to children.

      Parameters

      • rootObjectId: string
      • name: string

      Returns Promise<void>

      Async; O(subtree size) rebinds, serialized with other branch operations.

    • Fold main's changes into a branch across the subtree (the reverse of mergeBranch).

      Parameters

      • rootObjectId: string
      • name: string

      Returns Promise<void>

      Async; O(subtree size) Automerge merges, serialized with other branch operations.