|
27 | 27 | * T:LauncherIo type {stdin,stdout,stderr} override for launcher subprocess |
28 | 28 | * T:JsonSchemaObject type {[key:string]:unknown} plain JSON Schema object |
29 | 29 | * s.string/number/integer/boolean/null SchemaHelperFactory primitives; call as value or fn(desc) |
30 | | - * s.array(items,desc?) ArraySchema |
31 | | - * s.object(props,desc?) ObjectSchema; s.optional(inner) marks field optional |
32 | | - * s.record(valSchema,desc?) RecordSchema keyed by string |
| 30 | + * s.array(items,desc?) ArraySchema; use for homogeneous lists, e.g. s.array(s.string) |
| 31 | + * s.object(props,desc?) ObjectSchema; s.optional(inner) marks field optional; use for fixed-key shapes |
| 32 | + * s.record(valSchema,desc?) RecordSchema keyed by string; use for open-ended key→value maps |
33 | 33 | * s.enum(...values|values,desc) EnumSchema |
34 | 34 | * s.unknown() unconstrained JSON |
35 | 35 | * p`...` PromptBuilder template tag; interpolates PromptIntent|string|PromptBuilder |
@@ -202,15 +202,33 @@ export const s = { |
202 | 202 | null: createTypedPrimitiveSchema<NullSchema>("null"), |
203 | 203 | /** Schema for an unconstrained JSON value. Serializes to an empty schema object. */ |
204 | 204 | unknown: createUnknownSchema(), |
205 | | - /** Schema for a homogeneous array. `s.array(s.string)` → `string[]`. */ |
| 205 | + /** |
| 206 | + * Schema for a homogeneous array. |
| 207 | + * |
| 208 | + * @example |
| 209 | + * s.array(s.string) // string[] |
| 210 | + * s.array(s.number, "scores") // number[] with description |
| 211 | + */ |
206 | 212 | array<Item extends Schema>(items: Item, description?: string): ArraySchema<Item> { |
207 | 213 | return description === undefined ? markAsSchema({ type: "array", items }) : markAsSchema({ type: "array", items, description }); |
208 | 214 | }, |
209 | | - /** Schema for a fixed-shape object. Fields wrapped with `s.optional` are omitted from `required`. */ |
| 215 | + /** |
| 216 | + * Schema for a fixed-shape object. Fields wrapped with `s.optional` are omitted from `required`. |
| 217 | + * |
| 218 | + * @example |
| 219 | + * s.object({ name: s.string, age: s.optional(s.number) }) |
| 220 | + */ |
210 | 221 | object<Fields extends Record<string, Schema>>(properties: Fields, description?: string): ObjectSchema<Fields> { |
211 | 222 | return description === undefined ? markAsSchema({ type: "object", properties }) : markAsSchema({ type: "object", properties, description }); |
212 | 223 | }, |
213 | | - /** Schema for a string-keyed map where every value shares the same schema. */ |
| 224 | + /** |
| 225 | + * Schema for a string-keyed map where every value shares the same schema. |
| 226 | + * Use this instead of `s.object` when the keys are not known in advance. |
| 227 | + * |
| 228 | + * @example |
| 229 | + * s.record(s.string) // Record<string, string> |
| 230 | + * s.record(s.number, "score by name") // Record<string, number> with description |
| 231 | + */ |
214 | 232 | record<Value extends Schema>(additionalProperties: Value, description?: string): RecordSchema<Value> { |
215 | 233 | return description === undefined ? markAsSchema({ type: "object", additionalProperties }) : markAsSchema({ type: "object", additionalProperties, description }); |
216 | 234 | }, |
|
0 commit comments