Skip to content

Query

import { Order, Query } from '@dxos/echo';

A query selects a set of entities, then can step through the graph from that set: along reference fields, backwards to whatever references them, or across relations. Building a query does no work. It compiles to a query AST, and runs only when you pass it to db.query and read the result. org.dxos.echo#F-5.2

Most queries start from a type and a few field values. Query.select takes any filter; these three cover most uses, and Filter has the rest.

import {
import Filter
Filter
,
import Query
Query
} from '@dxos/echo';
import {
class Organization
Organization
,
class Person
Person
} from './schema.ts';
const
const people: Query.Query<Person & OfKind<EntityKind.Object>>
people
=
import Query
Query
.
const type: <typeof Person>(type: typeof Person, predicates?: Filter.Props<Person & OfKind<EntityKind.Object>> | undefined) => Query.Query<Person & OfKind<EntityKind.Object>> (+3 overloads)
type
(
class Person
Person
);
const
const acme: Query.Query<Organization & OfKind<EntityKind.Object>>
acme
=
import Query
Query
.
const select: <Filter.Filter<Organization & OfKind<EntityKind.Object>>>(filter: Filter.Filter<Organization & OfKind<EntityKind.Object>>) => Query.Query<Organization & OfKind<EntityKind.Object>>

Select objects based on a filter.

@param ― filter - Filter to select the objects.

@returns ― Query for the selected objects.

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

select
(
import Filter
Filter
.
const type: <typeof Organization>(type: typeof Organization, props?: Filter.Props<Organization & OfKind<EntityKind.Object>> | undefined) => Filter.Filter<Organization & OfKind<EntityKind.Object>> (+4 overloads)
type
(
class Organization
Organization
, {
name?: string | Filter.Filter<string> | undefined
name
: 'Acme' }));
const
const launches: Query.Query<any>
launches
=
import Query
Query
.
const select: <Filter.Any>(filter: Filter.Any) => Query.Query<any>

Select objects based on a filter.

@param ― filter - Filter to select the objects.

@returns ― Query for the selected objects.

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

select
(
import Filter
Filter
.
const text: (text: string, options?: Filter.TextSearchOptions) => Filter.Any

Full-text or vector search.

@performance ― O(1); builds a filter AST node without matching anything.

text
('launch'));

Query.all is the union of several queries. Query.without removes the results of one query from another.

import {
import Query
Query
} from '@dxos/echo';
import {
class Organization
Organization
,
class Person
Person
} from './schema.ts';
const
const peopleOrOrgs: Query.Any
peopleOrOrgs
=
import Query
Query
.
const all: (...queries: Query.Any[]) => Query.Any (+1 overload)

Combining queries over one type preserves it, so a union stays assignable where its arms were.

all
(
const people: Query.Query<Person & OfKind<EntityKind.Object>>
people
,
import Query
Query
.
const type: <typeof Organization>(type: typeof Organization, predicates?: Filter.Props<Organization & OfKind<EntityKind.Object>> | undefined) => Query.Query<Organization & OfKind<EntityKind.Object>> (+3 overloads)
type
(
class Organization
Organization
));
const
const withoutAda: Query.Query<Person & OfKind<EntityKind.Object>>
withoutAda
=
import Query
Query
.
const without: <Person & OfKind<EntityKind.Object>>(source: Query.Query<Person & OfKind<EntityKind.Object>>, exclude: Query.Query<Person & OfKind<EntityKind.Object>>) => Query.Query<Person & OfKind<EntityKind.Object>>

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.

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

without
(
const people: Query.Query<Person & OfKind<EntityKind.Object>>
people
,
import Query
Query
.
const type: <typeof Person>(type: typeof Person, predicates?: Filter.Props<Person & OfKind<EntityKind.Object>> | undefined) => Query.Query<Person & OfKind<EntityKind.Object>> (+3 overloads)
type
(
class Person
Person
, {
name?: string | Filter.Filter<string> | undefined
name
: 'Ada' }));

Each step returns a new query, so steps chain.

  • reference(field) follows a Ref field to its targets.
  • referencedBy(Type, field) goes the other way, to the objects whose field points at the selection.
  • sourceOf(Relation) and targetOf(Relation) select the relations that start or end at the selection.
  • source() and target() step from relations to their endpoints.
import {
class Person
Person
} from './schema.ts';
import {
class WorksAt
WorksAt
} from './works-at.ts';
const
const employers: Query.Query<Organization & OfKind<EntityKind.Object> & Unknown>
employers
=
const people: Query.Query<Person & OfKind<EntityKind.Object>>
people
.
Query<Person & OfKind<EntityKind.Object>>.reference<"employer">(key: "employer"): Query.Query<Organization & OfKind<EntityKind.Object> & Unknown>

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.

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

reference
('employer'); // follow a Ref field
const
const staff: Query.Query<Person & OfKind<EntityKind.Object>>
staff
=
const acme: Query.Query<Organization & OfKind<EntityKind.Object>>
acme
.
Query<Organization & OfKind<EntityKind.Object>>.referencedBy<typeof Person>(target: typeof Person | URI, key: RefPropKey<Person & OfKind<EntityKind.Object>>): Query.Query<Person & OfKind<EntityKind.Object>> (+2 overloads)

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.

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

referencedBy
(
class Person
Person
, 'employer'); // follow it backwards
// relations that end at Acme, and the people at their other end
const
const jobs: Query.Query<Endpoints<Person & OfKind<EntityKind.Object>, Organization & OfKind<EntityKind.Object>> & WorksAt & OfKind<EntityKind.Relation>>
jobs
=
const acme: Query.Query<Organization & OfKind<EntityKind.Object>>
acme
.
Query<Organization & OfKind<EntityKind.Object>>.targetOf<typeof WorksAt>(relation?: URI | typeof WorksAt | undefined, predicates?: Filter.Props<Endpoints<Person & OfKind<EntityKind.Object>, Organization & OfKind<EntityKind.Object>> & WorksAt & OfKind<EntityKind.Relation>> | undefined): Query.Query<Endpoints<Person & OfKind<EntityKind.Object>, Organization & OfKind<EntityKind.Object>> & WorksAt & OfKind<EntityKind.Relation>>

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.

@performance ― O(1) plus O(p) for predicates; builds the AST without executing anything.

targetOf
(
class WorksAt
WorksAt
);
const
const workers: Query.Query<Person & OfKind<EntityKind.Object>>
workers
=
const jobs: Query.Query<Endpoints<Person & OfKind<EntityKind.Object>, Organization & OfKind<EntityKind.Object>> & WorksAt & OfKind<EntityKind.Relation>>
jobs
.
Query<Endpoints<Person & OfKind<EntityKind.Object>, Organization & OfKind<EntityKind.Object>> & WorksAt & OfKind<...>>.source(): Query.Query<Person & OfKind<EntityKind.Object>>

For a query for relations, get the source objects.

@returns ― Query for the source objects.

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

source
();

orderBy takes one or more orders, applied in turn. org.dxos.echo#F-5.3 Order.property sorts by a field; Order.created and Order.updated sort by timestamp; Order.natural keeps insertion order.

import {
import Order
Order
} from '@dxos/echo';
import {
class Person
Person
} from './schema.ts';
const
const ordered: Query.Query<Person & OfKind<EntityKind.Object>>
ordered
=
const people: Query.Query<Person & OfKind<EntityKind.Object>>
people
.
Query<Person & OfKind<EntityKind.Object>>.orderBy(order_0: Order.Order<Person & OfKind<EntityKind.Object>>, ...order: Order.Order<Person & OfKind<EntityKind.Object>>[]): Query.Query<Person & OfKind<EntityKind.Object>>

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).

@param ― order - Order to sort the results.

@returns ― Query for the ordered results.

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

orderBy
(
import Order
Order
.
const property: <Person>(property: "email" | "employer" | "name" | "~@dxos/echo/Kind" | "id", direction: OrderDirection) => Order.Order<Person>

Order by a property of the current result shape.

@performance ― O(1); builds an order AST node without sorting anything.

property
<
class Person
Person
>('name', 'asc'),
import Order
Order
.
const updated: <Person & OfKind<EntityKind.Object>>(direction?: OrderDirection) => Order.Order<Person & OfKind<EntityKind.Object>>

Order by the system updatedAt timestamp (last re-indexed). Default direction is 'desc' (most-recently-updated first). Mirrors

Filter.updated

.

@performance ― O(1); builds an order AST node without sorting anything.

updated
())
.
Query<Person & OfKind<EntityKind.Object>>.limit(limit: number): Query.Query<Person & OfKind<EntityKind.Object>>

Limit the number of results.

@param ― limit - Maximum number of results to return.

@returns ― Query for the limited results.

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

limit
(20);

aggregate turns the results into records of named values: Aggregate.count, sum, min, max, group by a field, items for the members of each group, and created, updated or time bucketed by a unit. It must be the last step that selects data; only orderBy, limit, skip and from may follow it.

import {
import Aggregate
Aggregate
,
import Query
Query
} from '@dxos/echo';
import {
class Event
Event
} from './schema.ts';
const [{
const count: number
count
}] = await
const db: Database.Database
db
.
Database.query: Database.QueryFn
<Query.Query<{
readonly '~@dxos/echo/Query.RecordResult': true;
readonly count: number;
}>>(query: Query.Query<{
readonly '~@dxos/echo/Query.RecordResult': true;
readonly count: number;
}>) => QueryResult<{
readonly '~@dxos/echo/Query.RecordResult': true;
readonly count: number;
}> (+1 overload)
query
(
import Query
Query
.
const type: <typeof Event>(type: typeof Event, predicates?: Filter.Props<Event & OfKind<EntityKind.Object>> | undefined) => Query.Query<Event & OfKind<EntityKind.Object>> (+3 overloads)
type
(
class Event
Event
).
Query<Event & OfKind<EntityKind.Object>>.aggregate<{
readonly count: Aggregate.Aggregate<Event & OfKind<EntityKind.Object>, number>;
}>(aggregates: {
readonly count: Aggregate.Aggregate<Event & OfKind<EntityKind.Object>, number>;
}): Query.Query<{
readonly '~@dxos/echo/Query.RecordResult': true;
readonly count: number;
}>

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.

@param ― aggregates - Record of aggregate declarations keyed by result field name.

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

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

aggregate
({
count: Aggregate.Aggregate<Event & OfKind<EntityKind.Object>, number>
count
:
import Aggregate
Aggregate
.
const count: <Event & OfKind<EntityKind.Object>>() => Aggregate.Aggregate<Event & OfKind<EntityKind.Object>, number>

Count the group's members. Opt-in — groups carry no count unless this aggregate is declared.

@performance ― O(1); builds an aggregate spec without evaluating anything.

count
() }))
.
QueryResult<{ readonly '~@dxos/echo/Query.RecordResult': true; readonly count: number; }>.run(opts?: RunOptions): Promise<{
readonly '~@dxos/echo/Query.RecordResult': true;
readonly count: number;
}[]>

Returns all known results.

@performance ― Async; executes the full query (index plus working set) on every call, not cached; O(n) in the data the executor examines, not in the result count.

run
();

Without from, a query reads the database it runs on. from names the sources instead, with Scope: Scope.space() for a space, Scope.registry() for the types and objects registered in code, and Scope.feed() for a feed. from also takes a database, a feed object, or 'all-accessible-spaces'.

import {
import Filter
Filter
,
import Query
Query
,
import Scope
Scope
,
import Type
Type
} from '@dxos/echo';
// Types stored in the space, and types registered in code.
const
const types: ({
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & {
readonly id: string;
readonly "~@dxos/echo/Kind": EntityKind.Type;
readonly "~@dxos/echo/SchemaKind": EntityKind.Type;
readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>;
} & OfKind<EntityKind.Type>)[]
types
= await
const db: Database.Database
db
.
Database.query: Database.QueryFn
<Query.Query<{
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & {
readonly id: string;
readonly "~@dxos/echo/Kind": EntityKind.Type;
readonly "~@dxos/echo/SchemaKind": EntityKind.Type;
readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>;
} & OfKind<EntityKind.Type>>>(query: Query.Query<{
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & {
readonly id: string;
readonly "~@dxos/echo/Kind": EntityKind.Type;
readonly "~@dxos/echo/SchemaKind": EntityKind.Type;
readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>;
} & OfKind<EntityKind.Type>>) => QueryResult<...> (+1 overload)
query
(
import Query
Query
.
const select: <Filter.Filter<{
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & {
readonly id: string;
readonly "~@dxos/echo/Kind": EntityKind.Type;
readonly "~@dxos/echo/SchemaKind": EntityKind.Type;
readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>;
} & OfKind<EntityKind.Type>>>(filter: Filter.Filter<{
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & {
readonly id: string;
readonly "~@dxos/echo/Kind": EntityKind.Type;
readonly "~@dxos/echo/SchemaKind": EntityKind.Type;
readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>;
} & OfKind<EntityKind.Type>>) => Query.Query<...>

Select objects based on a filter.

@param ― filter - Filter to select the objects.

@returns ― Query for the selected objects.

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

select
(
import Filter
Filter
.
const type: <Type.Type<TypeSchema>>(type: Type.Type<TypeSchema>, props?: Filter.Props<{
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & {
readonly id: string;
readonly "~@dxos/echo/Kind": EntityKind.Type;
readonly "~@dxos/echo/SchemaKind": EntityKind.Type;
readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>;
} & OfKind<EntityKind.Type>> | undefined) => Filter.Filter<{
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & ... 1 more ... & OfKind<EntityKind.Type>> (+4 overloads)
type
(
import Type
Type
.
const Type: Type.Type<TypeSchema>

ECHO meta-schema entity — stores { name?, typename, version, jsonSchema }. Type-kind sibling of Type.makeObject(...) / Type.makeRelation(...) outputs. Stored types live under this entity; filter via Filter.type(Type.Type).

Sibling of

Obj

/

Relation

for the third ECHO entity kind: type-kind entities (meta-schemas). The singleton

Type

const is the canonical example — it describes stored type definitions themselves.

Not a Schema.Schema. Use Type.getSchema(value) to obtain the underlying Effect Schema and Type.update(value, draft => ...) to mutate.

A is the instance-type phantom — what Obj.make(value, ...) would produce. Merged with the Type const value via TypeScript declaration merging.

Type
)).
Query<{ readonly jsonSchema: JsonSchemaType; readonly name?: string | undefined; } & { readonly id: string; readonly "~@dxos/echo/Kind": EntityKind.Type; readonly "~@dxos/echo/SchemaKind": EntityKind.Type; readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>; } & OfKind<...>>.from(...scopes: Scope[]): Query.Query<{
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & {
readonly id: string;
readonly "~@dxos/echo/Kind": EntityKind.Type;
readonly "~@dxos/echo/SchemaKind": EntityKind.Type;
readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>;
} & OfKind<EntityKind.Type>> (+6 overloads)

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());

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

from
(
import Scope
Scope
.
const space: (options?: {
id?: string;
includeAllFeeds?: boolean;
}) => SpaceScope

Scope targeting a space's automerge documents.

With no spaceId, targets the owning space — i.e. the space of whichever database executes the query — so callers can reference "this space" without looking up its id.

@example

db.query(Filter.type(Person).from(Scope.space())); // owning space
db.query(Filter.type(Person).from(Scope.space({ id: otherSpaceId }))); // a specific space

@performance ― O(1); builds a scope node.

space
(),
import Scope
Scope
.
const registry: (location?: "local" | "remote") => RegistryScope

Scope targeting a code-shipped object/type registry.

  • 'local' — the in-process registry attached to the hypergraph (default).
  • 'remote' — a remote registry service (not yet implemented).

@example

// Discover all types — persisted in the space and code-shipped in the registry.
db.query(Filter.type(Type.Type).from(Scope.space(), Scope.registry()));

@performance ― O(1); builds a scope node.

registry
()),
)
.
QueryResult<{ readonly jsonSchema: JsonSchemaType; readonly name?: string | undefined; } & { readonly id: string; readonly "~@dxos/echo/Kind": EntityKind.Type; readonly "~@dxos/echo/SchemaKind": EntityKind.Type; readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>; } & OfKind<...>>.run(opts?: RunOptions): Promise<({
readonly jsonSchema: JsonSchemaType;
readonly name?: string | undefined;
} & {
readonly id: string;
readonly "~@dxos/echo/Kind": EntityKind.Type;
readonly "~@dxos/echo/SchemaKind": EntityKind.Type;
readonly "~@dxos/echo/Type.StaticSchema": Codec<any, any>;
} & OfKind<EntityKind.Type>)[]>

Returns all known results.

@performance ― Async; executes the full query (index plus working set) on every call, not cached; O(n) in the data the executor examines, not in the result count.

run
();

db.query returns a QueryResult. run() resolves with the results once. subscribe calls back each time the results change, and { fire: true } also calls it straight away with the current results. org.dxos.echo#F-5.1

A query reads the objects on this device first and adds what the indexes and EDGE return. A subscriber can see results arrive in more than one step. QueryResult.sources lists each source with its state: pending, answered or failed.

org.dxos.echo.query#F-5
const
const all: (Person & OfKind<EntityKind.Object>)[]
all
= await
const db: Database.Database
db
.
Database.query: Database.QueryFn
<Query.Query<Person & OfKind<EntityKind.Object>>>(query: Query.Query<Person & OfKind<EntityKind.Object>>) => QueryResult<Person & OfKind<EntityKind.Object>> (+1 overload)
query
(
const ordered: Query.Query<Person & OfKind<EntityKind.Object>>
ordered
).
QueryResult<Person & OfKind<EntityKind.Object>>.run(opts?: RunOptions): Promise<(Person & OfKind<EntityKind.Object>)[]>

Returns all known results.

@performance ― Async; executes the full query (index plus working set) on every call, not cached; O(n) in the data the executor examines, not in the result count.

run
();
const
const first: (Person & OfKind<EntityKind.Object>) | undefined
first
= await
const db: Database.Database
db
.
Database.query: Database.QueryFn
<Query.Query<Person & OfKind<EntityKind.Object>>>(query: Query.Query<Person & OfKind<EntityKind.Object>>) => QueryResult<Person & OfKind<EntityKind.Object>> (+1 overload)
query
(
const ordered: Query.Query<Person & OfKind<EntityKind.Object>>
ordered
).
QueryResult<Person & OfKind<EntityKind.Object>>.firstOrUndefined(opts?: RunOptions): Promise<(Person & OfKind<EntityKind.Object>) | undefined>

Returns first result if there is one.

@performance ― O(n) in the data examined: runs the full query and takes the first result; .limit(1) bounds the work only where the executor applies the limit before scanning.

firstOrUndefined
();
const
const result: QueryResult<Person & OfKind<EntityKind.Object>>
result
=
const db: Database.Database
db
.
Database.query: Database.QueryFn
<Query.Query<Person & OfKind<EntityKind.Object>>>(query: Query.Query<Person & OfKind<EntityKind.Object>>) => QueryResult<Person & OfKind<EntityKind.Object>> (+1 overload)
query
(
const ordered: Query.Query<Person & OfKind<EntityKind.Object>>
ordered
);
const
const unsubscribe: CleanupFn
unsubscribe
=
const result: QueryResult<Person & OfKind<EntityKind.Object>>
result
.
QueryResult<Person & OfKind<EntityKind.Object>>.subscribe(callback?: ((query: QueryResult<Person & OfKind<EntityKind.Object>>) => void) | undefined, opts?: SubscriptionOptions): CleanupFn

Subscribes to changes in query results.

@performance ― O(1) registration; the first subscriber starts the live query, whose updates cost an O(n) recompute.

subscribe
(
(
result: QueryResult<Person & OfKind<EntityKind.Object>>
result
) =>
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@see ― source

console
.
Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@since ― v0.1.100

log
(
result: QueryResult<Person & OfKind<EntityKind.Object>>
result
.
QueryResult<Person & OfKind<EntityKind.Object>>.results: (Person & OfKind<EntityKind.Object>)[]

Currently available results.

@performance ― Synchronous; O(n) recompute from the working set on first read after a change, cached otherwise.

results
.
Array<Person & OfKind<EntityKind.Object>>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
),
{
fire?: boolean | undefined

Fire the callback immediately.

fire
: true },
);
// Each source of the answer, with its state: pending, answered or failed.
const
const sources: readonly SourceState[]
sources
=
const result: QueryResult<Person & OfKind<EntityKind.Object>>
result
.
QueryResult<Person & OfKind<EntityKind.Object>>.sources: readonly SourceState[]

Per-source progress of the live query.

@performance ― O(sources); allocates.

sources
;
const unsubscribe: () => void
unsubscribe
();
Member Summary
select type Start a query from a filter or a type
all without Union and difference of queries
.reference .referencedBy Follow reference fields, forwards or backwards
.sourceOf .targetOf Relations that start or end at the selection
.source .target Endpoints of selected relations
.orderBy .limit .skip Order, cap and page the results
.aggregate Aggregate.* Count, sum, group and bucket the results
.from Scope.* Choose the sources
Order.property created updated Orders
QueryResult.run first subscribe Read the results
QueryResult.sources Each source and its state

The full list is in the API reference.