import type * as EffectArray from 'effect/Array'; import type * as Schema from 'effect/Schema'; import { type QueryAST } from '@dxos/echo-protocol'; import { type URI } from '@dxos/keys'; import * as Database from './Database'; import type * as Dataset from './Dataset'; import * as Feed from './Feed'; import * as Filter from './Filter'; import * as internal from './internal'; import type * as Order from './Order'; import type * as Ref from './Ref'; import type * as Relation from './Relation'; import type * as Type$ from './Type'; /** * All property paths inside T that are references. */ type RefPropKey = keyof T & string; type RefArrayElement = A extends readonly (infer E)[] ? E : A extends (infer E)[] ? E : never; /** Target entity when traversing an outgoing ref or array-of-refs property. */ type ReferenceTraversalTarget

= P extends Ref.Unknown ? Ref.Target

: P extends Ref.Unknown | undefined ? Ref.Target> : RefArrayElement

extends Ref.Unknown ? Ref.Target> : never; export interface Query { '~Query': { value: T; }; ast: QueryAST.Query; /** * Filter the current selection based on a filter. * @param filter - Filter to select the objects. * @returns Query for the selected objects. */ 'select'(filter: Filter.Filter): Query; 'select'(props: Filter.Props): Query; /** * Traverse an outgoing reference. * @param key - Property path inside T that is a reference or optional reference. * @returns Query for the target of the reference. */ 'reference'>(key: K): Query>; /** * Find objects referencing this object. * @param target - Schema of the referencing object. If not provided, matches any type. * @param key - Property path inside the referencing object that is a reference. If not provided, matches any property. * @returns Query for the referencing objects. */ 'referencedBy'(target: S | URI.URI, key: RefPropKey>): Query>; 'referencedBy'(target: S | URI.URI): Query>; 'referencedBy'(): Query; /** * Find relations where this object is the source. * @returns Query for the relation objects. * @param relation - Schema of the relation. * @param predicates - Predicates to filter the relation objects. */ 'sourceOf'(relation?: R | URI.URI, predicates?: Filter.Props>): Query>; /** * Find relations where this object is the target. * @returns Query for the relation objects. * @param relation - Type entity of the relation. * @param predicates - Predicates to filter the relation objects. */ 'targetOf'(relation?: R | URI.URI, predicates?: Filter.Props>): Query>; /** * For a query for relations, get the source objects. * @returns Query for the source objects. */ 'source'(): Query>; /** * For a query for relations, get the target objects. * @returns Query for the target objects. */ 'target'(): Query>; /** * Get the parent object of the current selection. * @returns Query for the parent objects. */ 'parent'(): Query; /** * Get all child objects of the current selection. * @returns Query for the child objects. */ 'children'(): Query; /** * Order the query results. * Orders are specified in priority order. The first order will be applied first, etc. * @param order - Order to sort the results. * @returns Query for the ordered results. */ 'orderBy'(...order: EffectArray.NonEmptyArray>): Query; /** * Limit the number of results. * @param limit - Maximum number of results to return. * @returns Query for the limited results. */ 'limit'(limit: number): Query; /** * Query from selected databases only. * * Example: * * ```ts * Query.select(Filter.type(Person)).from(db); * ``` * * @param options.includeFeeds [false] - Whether to include feeds in the query. Default is to query from automerge documents only. */ 'from'(database: Database.Database | Database.Database[], options?: { includeFeeds?: boolean; }): Query; /** * Query from selected feeds only. * * Example: * * ```ts * Query.select(Filter.type(Person)).from(feed); * ``` * */ 'from'(feeds: Feed.Feed | Feed.Feed[]): Query; /** * Query from all accessible spaces. * * Example: * * ```ts * Query.select(Filter.type(Person)).from('all-accessible-spaces'); * ``` * * @param options.includeFeeds [false] - Whether to include feeds in the query. Default is to query from automerge documents only. */ 'from'(allSpaces: 'all-accessible-spaces', options?: { includeFeeds?: boolean; }): Query; /** * Query from a dataset. * Currently only feeds are supported. * * Example: * * ```ts * Query.type(Person).from(feed); * ``` */ 'from'(dataset: Dataset.Dataset): Query; /** * Query from the results of another query. * * Example: * * ```ts * Query.select(Filter.props({ foo: 'foo' })).from(Query.select(Filter.type(Contact)).reference('org')); * ``` */ 'from'(query: Any): Query; /** * Query from one or more raw scopes. * * Use the {@link Scope} constructors rather than raw tagged objects: * * ```ts * Query.select(Filter.type(Type.Type)).from(Scope.space(), Scope.registry()); * ``` */ 'from'(...scopes: QueryAST.Scope[]): Query; /** * Query from a raw scope or array of scopes. */ 'from'(scope: QueryAST.Scope | QueryAST.Scope[]): Query; /** * Add options to a query. */ 'options'(options: QueryAST.QueryOptions): Query; /** * Attach a diagnostic label for logs and tooling (execution semantics unchanged). */ 'debugLabel'(label: string): Query; } export type Any = Query; export type Type = Q extends Query ? T : never; export declare const is: (value: unknown) => value is Any; /** Construct a query from an ast. */ export declare const fromAst: (ast: QueryAST.Query) => Any; /** * Select objects based on a filter. * @param filter - Filter to select the objects. * @returns Query for the selected objects. */ export declare const select: (filter: F) => Query>; /** * Query for objects of a given schema. * @param schema - Schema of the objects. * @param predicates - Predicates to filter the objects. * @returns Query for the objects. * * Shorthand for: `Query.select(Filter.type(schema, predicates))`. */ export declare const type: { (type: T, predicates?: Filter.Props>): Query>; >(schema: S, predicates?: Filter.Props>): Query>; >(union: S, predicates?: Filter.Props>): Query>; (uri: URI.URI, predicates?: Filter.Props): Query; }; /** * Combine results of multiple queries. * @param queries - Queries to combine. * @returns Query for the combined results. */ export declare const all: (...queries: Any[]) => Any; /** * Subtract one query from another. * @param source - Query to subtract from. * @param exclude - Query to subtract. * @returns Query for the results of the source query minus the results of the exclude query. */ export declare const without: (source: Query, exclude: Query) => Query; /** * Create a query scoped to a data source. * The returned query selects everything from the source; chain `.select()` to narrow results. * * @param source - Data source: database, feed, 'all-accessible-spaces', or another query. * @returns Query scoped to the given source. */ export declare const from: (...args: [(Database.Database | Database.Database[] | Feed.Feed | Feed.Feed[] | Any | QueryAST.Scope | QueryAST.Scope[] | 'all-accessible-spaces'), { includeFeeds?: boolean; }?] | QueryAST.Scope[]) => Any; /** * Returns a human-readable string representation of a Query AST. */ export declare const pretty: (query: Any) => string; export {}; //# sourceMappingURL=Query.d.ts.map