···6061you could also access the json definition with `lex.json()`.
6200000000000000000000000000000000000000000000000000000000000063### CLI Commands
6465The `prototypey` package includes a CLI with two main commands:
···6061you could also access the json definition with `lex.json()`.
6263+### Runtime Validation
64+65+Prototypey provides runtime validation using [@atproto/lexicon](https://www.npmjs.com/package/@atproto/lexicon):
66+67+```ts
68+const lex = lx.lexicon("app.bsky.actor.profile", {
69+ main: lx.record({
70+ key: "self",
71+ record: lx.object({
72+ displayName: lx.string({ maxLength: 64, maxGraphemes: 64 }),
73+ description: lx.string({ maxLength: 256, maxGraphemes: 256 }),
74+ }),
75+ }),
76+});
77+78+// Validate data against the schema
79+const result = lex.validate({
80+ displayName: "Alice",
81+ description: "Software engineer",
82+});
83+84+if (result.success) {
85+ console.log("Valid data:", result.value);
86+} else {
87+ console.error("Validation error:", result.error);
88+}
89+```
90+91+**Validating against specific definitions:**
92+93+If your lexicon has multiple definitions, you can validate against a specific one:
94+95+```ts
96+const lex = lx.lexicon("app.bsky.feed.post", {
97+ user: lx.object({
98+ handle: lx.string({ required: true }),
99+ displayName: lx.string(),
100+ }),
101+ main: lx.record({
102+ key: "tid",
103+ record: lx.object({
104+ text: lx.string({ required: true }),
105+ author: lx.ref("#user", { required: true }),
106+ }),
107+ }),
108+});
109+110+// Validate against the "user" definition
111+const userResult = lex.validate(
112+ { handle: "alice.bsky.social", displayName: "Alice" },
113+ "user",
114+);
115+116+// Validate against "main" (default if not specified)
117+const postResult = lex.validate({
118+ text: "Hello world",
119+ author: { handle: "bob.bsky.social" },
120+});
121+```
122+123### CLI Commands
124125The `prototypey` package includes a CLI with two main commands: