Strata · API

upgrader.locate

upgrader.locate returns every document found inside a document, the root included, each with its kind and its path. A grammar declares where documents nest in each kind with embeds: a path is keys joined by dots, where * matches every value of a record and [] every item of an array. Strata uses this to apply a step written for one kind to every document of that kind, at any depth.

Grammar kinds (nisc.nova)
{
  action: {
    embeds: {
      layout: 'nisc.nova/layout',
      endpoints.*.request: 'nisc.prism/config',
      endpoints.*.response: 'nisc.prism/config',
    },
  },
  layout: {
    embeds: {
      children: 'nisc.nova/layout',
      children[]: 'nisc.nova/layout',
      then: 'nisc.nova/layout',
      else: 'nisc.nova/layout',
      do: 'nisc.nova/layout',
    },
  },
}
Document (nisc.nova/action)
{
  id: 'boxoffice.book',
  layout: {
    component: 'Stack',
    children: [
      { component: 'Text', children: 'The Tempest' },
      { component: 'Button', props: { text: 'Book seats' } },
    ],
  },
  endpoints: {
    book: {
      url: '/api/bookings',
      method: 'POST',
      request: {
        night: { $ref: '$.night' },
        seats: { $ref: '$.seats' },
      },
    },
  },
}
Located documents
[
  { kind: 'nisc.nova/action', path: [] },
  { kind: 'nisc.nova/layout', path: ['layout'] },
  { kind: 'nisc.nova/layout', path: ['layout', 'children', 0] },
  { kind: 'nisc.nova/layout', path: ['layout', 'children', 1] },
  { kind: 'nisc.prism/config', path: ['endpoints', 'book', 'request'] },
]
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.