@dxos/echo
    Preparing search index...

    Interface Query<T>

    interface Query<T> {
        "~@dxos/echo/Query": { value: T };
        ast:
            | QueryAST.QueryAggregateClause
            | QueryAST.QueryFilterClause
            | QueryAST.QueryFromClause
            | QueryAST.QueryHierarchyTraversalClause
            | QueryAST.QueryIncomingReferencesClause
            | QueryAST.QueryLimitClause
            | QueryAST.QueryOptionsClause
            | QueryAST.QueryOrderClause
            | QueryAST.QueryReferenceTraversalClause
            | QueryAST.QueryRelationClause
            | QueryAST.QueryRelationTraversalClause
            | QueryAST.QuerySelectClause
            | QueryAST.QuerySetDifferenceClause
            | QueryAST.QuerySkipClause
            | QueryAST.QueryUnionClause;
        aggregate<const A extends Record<string, Aggregate.Aggregate<T, any>>>(
            aggregates: A,
        ): Query.Query<
            Simplify<
                RecordResult & {
                    readonly [N in string
                    | number
                    | symbol]: ValueOf<A[N]>
                },
            >,
        >;
        children(): Query.Query<any>;
        debugLabel(label: string): Query.Query<T>;
        from(
            database: Database.Database | Database.Database[],
            options?: { includeFeeds?: boolean },
        ): Query.Query<T>;
        from(feeds: Feed.Feed | Feed.Feed[]): Query.Query<T>;
        from(
            allSpaces: "all-accessible-spaces",
            options?: { includeFeeds?: boolean },
        ): Query.Query<T>;
        from(dataset: Dataset.Dataset): Query.Query<T>;
        from(query: Query.Any): Query.Query<T>;
        from(
            ...scopes: (
                | { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
                | {
                    _tag: "feed";
                    branches?: "all" | readonly (null | string)[];
                    feedUri: string;
                    walk?: { branch?: null | string; forks?: boolean };
                }
                | { _tag: "registry"; location: "local"
                | "remote" }
            )[],
        ): Query.Query<T>;
        from(
            scope:
                | { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
                | {
                    _tag: "feed";
                    branches?: "all" | readonly (null | string)[];
                    feedUri: string;
                    walk?: { branch?: null | string; forks?: boolean };
                }
                | { _tag: "registry"; location: "local"
                | "remote" }
                | (
                    | { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
                    | {
                        _tag: "feed";
                        branches?: "all" | readonly (null | string)[];
                        feedUri: string;
                        walk?: { branch?: null | string; forks?: boolean };
                    }
                    | { _tag: "registry"; location: "local"
                    | "remote" }
                )[],
        ): Query.Query<T>;
        limit(limit: number): Query.Query<T>;
        options(options: QueryAST.QueryOptions): Query.Query<T>;
        orderBy(...order: [Order.Order<T>, ...Order.Order<T>[]]): Query.Query<T>;
        parent(): Query.Query<any>;
        project<K extends string>(property: K): Query.Projection<T[K]>;
        reference<K extends string>(
            key: K,
        ): Query.Query<ReferenceTraversalTarget<T[K]>>;
        referencedBy<S extends AnyEntity>(
            target: URI.URI | S,
            key: RefPropKey<InstanceType<S>>,
        ): Query.Query<InstanceType<S>>;
        referencedBy<S extends AnyEntity>(
            target: URI.URI | S,
        ): Query.Query<InstanceType<S>>;
        referencedBy(): Query.Query<any>;
        select(filter: Filter.Filter<T>): Query.Query<T>;
        select(props: Props<T>): Query.Query<T>;
        skip(skip: number): Query.Query<T>;
        source(): Query.Query<SourceOf<T>>;
        sourceOf<R extends AnyRelation>(
            relation?: URI.URI | R,
            predicates?: Props<InstanceType<R>>,
        ): Query.Query<InstanceType<R>>;
        target(): Query.Query<TargetOf<T>>;
        targetOf<R extends AnyRelation>(
            relation?: URI.URI | R,
            predicates?: Props<InstanceType<R>>,
        ): Query.Query<InstanceType<R>>;
    }

    Type Parameters

    • T
    Index

    Properties

    "~@dxos/echo/Query": { value: T }

    Methods

    • Aggregate the query results into flat records. Aggregate.group entries partition the results into contiguous groups (one record each), keyed by the record field the group is named after; with no group entries the entire input aggregates into a single record. Each declared aggregate becomes a top-level field and can be ordered by with a following orderBy using Order.property.

      Groups are ordered by the first occurrence of their key in the incoming stream, so a preceding orderBy controls group order in the absence of a following one. Aggregate.items's own order option is a separate, explicit per-group member ordering — pass it there rather than relying on a preceding orderBy, whose only well-defined job once aggregate follows is establishing initial group order. For example, message threads ordered by their most recent message, each retaining up to 20 members newest-first:

      Query.type(Message)
      .aggregate({
      threadId: Aggregate.group('threadId'),
      lastMessageAt: Aggregate.max('created'),
      items: Aggregate.items({ limit: 20, order: [Order.property('created', 'desc')] }),
      })
      .orderBy(Order.property('lastMessageAt', 'desc'));

      Must be the last data-selecting clause in the chain — only from/options/orderBy/limit/ skip may follow.

      Type Parameters

      Parameters

      • aggregates: A

        Record of aggregate declarations keyed by result field name.

      Returns Query.Query<
          Simplify<
              RecordResult & {
                  readonly [N in string
                  | number
                  | symbol]: ValueOf<A[N]>
              },
          >,
      >

      Query whose flat result records carry the named aggregates as fields.

      O(k) in the number of aggregates; builds the AST without executing anything.

    • Query from selected databases only.

      Example:

      Query.select(Filter.type(Person)).from(db);
      

      Parameters

      • database: Database.Database | Database.Database[]
      • Optionaloptions: { includeFeeds?: boolean }
        • OptionalincludeFeeds?: boolean

          [false] - Whether to include feeds in the query. Default is to query from automerge documents only.

      Returns Query.Query<T>

      O(k) in the number of sources; builds the AST without executing anything.

    • Query from selected feeds only.

      Example:

      Query.select(Filter.type(Person)).from(feed);
      

      Parameters

      Returns Query.Query<T>

      O(k) in the number of sources; builds the AST without executing anything.

    • Query from all accessible spaces.

      Example:

      Query.select(Filter.type(Person)).from('all-accessible-spaces');
      

      Parameters

      • allSpaces: "all-accessible-spaces"
      • Optionaloptions: { includeFeeds?: boolean }
        • OptionalincludeFeeds?: boolean

          [false] - Whether to include feeds in the query. Default is to query from automerge documents only.

      Returns Query.Query<T>

      O(1); wraps the current AST in a new immutable node without executing anything.

    • Query from a dataset. Currently only feeds are supported.

      Example:

      Query.type(Person).from(feed);
      

      Parameters

      Returns Query.Query<T>

      O(1); wraps the current AST in a new immutable node without executing anything.

    • Query from the results of another query.

      Example:

      Query.select(Filter.props({ foo: 'foo' })).from(Query.select(Filter.type(Contact)).reference('org'));
      

      Parameters

      Returns Query.Query<T>

      O(1); wraps the current AST in a new immutable node without executing anything.

    • Query from one or more raw scopes.

      Use the Scope constructors rather than raw tagged objects:

      Query.select(Filter.type(Type.Type)).from(Scope.space(), Scope.registry());
      

      Parameters

      • ...scopes: (
            | { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
            | {
                _tag: "feed";
                branches?: "all" | readonly (null | string)[];
                feedUri: string;
                walk?: { branch?: null | string; forks?: boolean };
            }
            | { _tag: "registry"; location: "local"
            | "remote" }
        )[]
        • { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
        • {
              _tag: "feed";
              branches?: "all" | readonly (null | string)[];
              feedUri: string;
              walk?: { branch?: null | string; forks?: boolean };
          }
          • Readonly_tag: "feed"
          • Optional Readonlybranches?: "all" | readonly (null | string)[]

            Restricts the read to items that are members of these branches: a branch id, or null for the main branch. Absent reads the main branch only, so a private branch never reaches a reader that did not ask for it; 'all' reads every branch.

          • ReadonlyfeedUri: string
          • Optional Readonlywalk?: { branch?: null | string; forks?: boolean }

            Reads the feed as a walk along the path from the root branch to branch (null or absent: the root branch, or on a backward walk the branch of the cursor), in local order, each item once at its latest block on the path. 'all' walks every branch of the feed in local order. forks also gives the base item of each branch that forks at a block the walk gives.

        • { _tag: "registry"; location: "local" | "remote" }

      Returns Query.Query<T>

      O(k) in the number of scopes; builds the AST without executing anything.

    • Query from a raw scope or array of scopes.

      Parameters

      • scope:
            | { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
            | {
                _tag: "feed";
                branches?: "all" | readonly (null | string)[];
                feedUri: string;
                walk?: { branch?: null | string; forks?: boolean };
            }
            | { _tag: "registry"; location: "local"
            | "remote" }
            | (
                | { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
                | {
                    _tag: "feed";
                    branches?: "all" | readonly (null | string)[];
                    feedUri: string;
                    walk?: { branch?: null | string; forks?: boolean };
                }
                | { _tag: "registry"; location: "local"
                | "remote" }
            )[]
        • { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
        • {
              _tag: "feed";
              branches?: "all" | readonly (null | string)[];
              feedUri: string;
              walk?: { branch?: null | string; forks?: boolean };
          }
          • Readonly_tag: "feed"
          • Optional Readonlybranches?: "all" | readonly (null | string)[]

            Restricts the read to items that are members of these branches: a branch id, or null for the main branch. Absent reads the main branch only, so a private branch never reaches a reader that did not ask for it; 'all' reads every branch.

          • ReadonlyfeedUri: string
          • Optional Readonlywalk?: { branch?: null | string; forks?: boolean }

            Reads the feed as a walk along the path from the root branch to branch (null or absent: the root branch, or on a backward walk the branch of the cursor), in local order, each item once at its latest block on the path. 'all' walks every branch of the feed in local order. forks also gives the base item of each branch that forks at a block the walk gives.

        • { _tag: "registry"; location: "local" | "remote" }
        • (
              | { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
              | {
                  _tag: "feed";
                  branches?: "all" | readonly (null | string)[];
                  feedUri: string;
                  walk?: { branch?: null | string; forks?: boolean };
              }
              | { _tag: "registry"; location: "local"
              | "remote" }
          )[]
          • { _tag: "space"; includeAllFeeds?: boolean; spaceId?: string }
          • {
                _tag: "feed";
                branches?: "all" | readonly (null | string)[];
                feedUri: string;
                walk?: { branch?: null | string; forks?: boolean };
            }
            • Readonly_tag: "feed"
            • Optional Readonlybranches?: "all" | readonly (null | string)[]

              Restricts the read to items that are members of these branches: a branch id, or null for the main branch. Absent reads the main branch only, so a private branch never reaches a reader that did not ask for it; 'all' reads every branch.

            • ReadonlyfeedUri: string
            • Optional Readonlywalk?: { branch?: null | string; forks?: boolean }

              Reads the feed as a walk along the path from the root branch to branch (null or absent: the root branch, or on a backward walk the branch of the cursor), in local order, each item once at its latest block on the path. 'all' walks every branch of the feed in local order. forks also gives the base item of each branch that forks at a block the walk gives.

          • { _tag: "registry"; location: "local" | "remote" }

      Returns Query.Query<T>

      O(k) in the number of scopes; builds the AST without executing anything.

    • Limit the number of results.

      Parameters

      • limit: number

        Maximum number of results to return.

      Returns Query.Query<T>

      Query for the limited results.

      O(1); wraps the current AST in a new immutable node without executing anything.

    • Order the query results. Orders are specified in priority order. The first order will be applied first, etc.

      Order.property orders by the current result shape's fields, so it works both before and after an aggregate: before, by member (row) properties; after, by the flat record's fields (any group or aggregate field — e.g. Order.property('lastMessageAt') reorders the groups by that aggregate).

      Parameters

      Returns Query.Query<T>

      Query for the ordered results.

      O(k) in the number of orders; builds the AST without executing anything.

    • Project the query's results to a single scalar property, for use as a membership set in Filter.in(query.project('col')) — an uncorrelated col IN (SELECT property FROM ...) semi-join. The subquery is resolved once at execution time. A projection is a terminal value, not a Query, so it cannot be chained further.

      Type Parameters

      • K extends string

      Parameters

      • property: K

        Property path to project.

      Returns Query.Projection<T[K]>

      O(1); wraps the current AST in a new immutable node without executing anything.

    • Traverse an outgoing reference.

      Type Parameters

      • K extends string

      Parameters

      • key: K

        Property path inside T that is a reference or optional reference.

      Returns Query.Query<ReferenceTraversalTarget<T[K]>>

      Query for the target of the reference.

      O(1); wraps the current AST in a new immutable node without executing anything.

    • Skip a number of results (offset). Combined with orderBy and limit, expresses a windowed (paginated) read.

      Parameters

      • skip: number

        Number of leading results to skip.

      Returns Query.Query<T>

      Query for the remaining results.

      O(1); wraps the current AST in a new immutable node without executing anything.