APIDemo

Pages

A pages instance is used to query the data stored in the cms.

Retrieving a page

A single page can be fetched using the findFirst method. Criteria can be passed to filter entries.

// Fetch the first page where field equals the string 'value'
const page: AnyPage | undefined = await pages
  .findFirst(page => page.field.is('value'))

Retrieving multiple pages

Multiple pages can be fetched using the findMany method.

// Fetch all pages where field equals the string 'value'
const pages: Array<AnyPage> = await pages
  .findMany(page => page.field.is('value'))

Limiting results

A result set can be limited using skip and take.

// Skip the first 10 pages and return a maximum of 10
const limited = await pages
  .all()
  .skip(10)
  .take(10)

Ordering results

A result set can be ordered by passing one or multiple fields.

const ordered = await pages
  .all()
  .orderBy(Type.foo.asc(), Type.bar.desc())

Group by

Results can be grouped by one or more fields.

const grouped = await pages
  .all()
  .groupBy(Type.foo, Type.bar)

Selecting specific fields

Resulting rows can be narrowed to contain only specific fields.

// Return only titles
const rows = await pages
  .all()
  .select(page => ({
    title: page.title
  })

Processing fields

It's possible to process field values by passing a function, which can be async.

const row = await pages
  .findFirst()
  .select(page => ({
    title: 
      page.title.process(title => `process title ${title}`)
  })

Types