Skip to content

ItemCursorSelector

Selects Items of any Template with cursor paging, as returned by selectItems on a context and selectChildren on an Item.

Narrow the selection to a Template or Union with template, union, prn or only to unlock Property filters, sorting and joins.

Data model

TItem

The type of each result.

archived(include): this

Chooses whether archived Items are left out, included, or the only results.

boolean | "exclude" | "include" | "only"

true or 'include' to include archived Items, 'only' for archived Items alone, false or 'exclude' to leave them out.

this

Archived Items are left out until this is called.

BaseSelector.archived


assign(input): this

Applies the criteria of an ItemQuery, such as one received from a client, over the current criteria.

ItemQuery

The query to apply; it is validated before use.

this

when input is not a valid ItemQuery.

BaseSelector.assign


cursor(value): this

Resumes the selection from a cursor returned with an earlier page.

CursorInput

The cursor, a cursor with a new page size, or undefined to start from the beginning.

this

when called on a selection that has switched to offset pagination.

CursorSelector.cursor


debug(): this

Logs the resolved query when the selection runs.

this

BaseSelector.debug


execute(): Promise<CursorSelectorResult<TItem>>

Runs the selection and returns one page of results with the cursor for the next page.

Promise<CursorSelectorResult<TItem>>

CursorSelector.execute


exists(): Promise<boolean>

Checks whether anything matches the selection, without ordering or reading the results, so the database can stop at the first match.

Promise<boolean>

Whether at least one Item matches.

Cheaper than first() on a large set of matches, which sorts every match to find the first. Unlike first() and execute(), the check is not permission filtered: it is true when an Item matches whatever the active principal can read (as with totalCount of a paginated selection). Run it with sudo for a yes/no question about Items the principal may not read.

BaseSelector.exists


filter(condition): this

Restricts results to Items satisfying a condition on their Properties or Relations.

ItemFilter

A Property condition ($equals, $in, $includes, $range), a Relation condition ($exists, $notExists) or a logical combination ($and, $or, $not).

this

when the condition is malformed, or (error-015-property-not-indexed) when a Property condition is used before the selection is narrowed to a Template or Union.

Match a Property value

const match = await participant.selectItems().filter({ operator: '$equals', key: 'slackUserId', value: input.slackUserId }).first();

BaseFilterSelector.filter


first(): Promise<TItem | undefined>

Runs the selection for a single result.

Promise<TItem | undefined>

The first result, or undefined when nothing matches.

CursorSelector.first


id(itemOrItems): this

Restricts results to the given Items.

SelectorIdInput

One or more identifiers; an empty list matches nothing.

this

BaseSelector.id


iterator(): AsyncGenerator<TItem, void, undefined>

Yields every result across all pages, fetching each page on demand at the current page size.

AsyncGenerator<TItem, void, undefined>

Walk every child of a Template

for await (const group of item.selectChildren().template(demographicGroup).iterator()) {
// ...
}

CursorSelector.iterator


key(key): this

Restricts results to Items carrying one of the given keys.

string | string[]

One or more keys; each must be a valid key.

this

BaseSelector.key


limit(value): this

Sets the page size.

number

A positive integer.

this

(error-008-invalid-selector-limit) when value is not a positive integer.

CursorSelector.limit


only(template): TemplateItemCursorSelector<TItem>

Narrows the selection to exactly one Template or Union, replacing any earlier narrowing.

The Template or Union.

string

TemplateItemCursorSelector<TItem>


onlyPrn(prn): TemplateItemCursorSelector<TItem>

Narrows the selection to the given Template or Union PRNs, replacing any given earlier.

string | string[]

One or more Template or Union PRNs.

TemplateItemCursorSelector<TItem>


paginate(options): ItemPaginateSelector<TItem>

Switches the selection to offset paging for one page.

PaginateOptions

The 1-based page and page size.

ItemPaginateSelector<TItem>

(error-008-invalid-selector-limit) when the page size is not a positive integer.


parent(parentOrParents): this

Restricts results to direct children of the given parents.

SelectorIdInput

One or more parent identifiers; an empty list matches nothing.

this

BaseSelector.parent


prn(prn): TemplateItemCursorSelector<TItem>

Narrows the selection to Items of the given Template or Union PRNs, in addition to any given earlier.

string | string[]

One or more Template or Union PRNs.

TemplateItemCursorSelector<TItem>


search(idx, query): this

Restricts results to Items matching a search query against a search index.

ReadSearchIndexInstance

The search index to query.

SearchQuery

The term and facets to match.

this

BaseSelector.search


state(state): this

Restricts results to Items in one of the given states.

string | string[]

One or more state keys; an empty list removes the state criterion.

this

BaseSelector.state


template(template): TemplateItemCursorSelector<TItem>

Narrows the selection to Items of a Template, in addition to any Templates or Unions given earlier.

The Template.

string

TemplateItemCursorSelector<TItem>


union(template): TemplateItemCursorSelector<TItem>

Narrows the selection to Items of a Union’s member Templates, in addition to any Templates or Unions given earlier.

The Union.

string

TemplateItemCursorSelector<TItem>