Prism · Transform

$assert

Gives value when when is truthy, and otherwise refuses with E_ASSERT and the message. It is how a config says what it will not work on.

The source
{ document: { id: 'todos.list', title: 'Todos' } }
The config
{
  $assert: {
    when: { $has: { from: { $ref: '$.document' }, path: ['id'] } },
    message: 'A document without an id cannot be migrated.',
    value: { $ref: '$.document' },
  },
}
What comes out
{ id: 'todos.list', title: 'Todos' }
Output matches the expected value

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