mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 15:26:25 +00:00
Keep item schemas when compact inputs reduce nested structure, expose literal tuple elements to items-first renderers, and preserve SQLite table-selection guidance across compaction. Verify catalog-wide client constraints and canonical rejection before dispatch. Document the stock Pi renderer size limit and caller-selected recovery.
15 lines
583 B
TypeScript
15 lines
583 B
TypeScript
import { z } from "zod";
|
|
|
|
/** Fixed tuples with explicit item and length constraints in JSON Schema. */
|
|
export const fixedTupleSchema = <
|
|
const Items extends readonly [z.ZodType, ...z.ZodType[]],
|
|
>(
|
|
items: Items,
|
|
): z.ZodTuple<Items, z.ZodUnion<Items>> =>
|
|
// Keep the positional schemas and lengths explicit. The union rest schema
|
|
// gives clients that only understand `items` useful element guidance; the
|
|
// exact maximum length means no rest element can be accepted.
|
|
z
|
|
.tuple(items, z.union(items))
|
|
.check(z.minLength(items.length), z.maxLength(items.length));
|