Strata · API

snapshotOf

snapshotOf, from @niscorp/strata/check, returns a snapshot of one grammar: its sequence id, its version and the JSON Schema of each kind, to be recorded in a file beside the code. Each schema is converted through its own Standard JSON Schema hook, as the validator emits it, with its keys sorted. The schemas passed must cover exactly the grammar’s kinds, each keyed <sequence>/<kind>.

Grammar
{
  id: 'theatre.buttons',
  documents: { button: {} },
  migrations: [
    {
      description: 'label is now text',
      steps: [
        {
          kind: 'document',
          at: 'theatre.buttons/button',
          transform: {
            $renameKeys: { from: { $ref: '$.document' }, map: { label: 'text' } },
          },
        },
      ],
    },
  ],
}
Schema
z.object({
  text: z.string(),
  tone: z.enum(['primary', 'quiet']).optional(),
}).strict()
Snapshot
{
  sequence: 'theatre.buttons',
  version: 1,
  kinds: {
    theatre.buttons/button: {
      $schema: 'https://json-schema.org/draft/2020-12/schema',
      additionalProperties: false,
      properties: {
        text: { type: 'string' },
        tone: { enum: ['primary', 'quiet'], type: 'string' },
      },
      required: ['text'],
      type: 'object',
    },
  },
}
Output matches the expected value

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