ConstKeypathSchema.parse('foo.bar'); // ✓ Valid
KeypathSchema.parse('arr[0].item'); // ✓ Valid
KeypathSchema.parse('obj["key"].prop'); // ✓ Valid
KeypathSchema.parse("obj['key'].prop"); // ✓ Valid
KeypathSchema.parse('simpleKey'); // ✓ Valid
KeypathSchema.parse('42'); // ✓ Valid
KeypathSchema.parse('invalid keypath!'); // ✗ Throws validation error
KeypathSchema.parse('foo..bar'); // ✗ Throws validation error
KeypathSchema.parse('foo[bar]'); // ✗ Throws validation error
KeypathSchema.parse(42); // ✗ Throws validation error
import { createAssertion, use } from 'bupkis';
import { KeypathSchema } from 'bupkis/schema';
const hasKeypathAssertion = createAssertion(
  [KeypathSchema, 'to be a keypath'],
  KeypathSchema,
);
const { expect } = use([hasKeypathAssertion]);
expect('foo.bar[0]["baz"]', 'to be a keypath');
A Zod schema that validates a keypath, which is a string featuring dot notation or bracket notation, used to access nested object properties.
Bare numbers must be wrapped in a string.