Skip to content

Commit 2027ba8

Browse files
authored
Merge pull request #17 from githubnext/rig-sampler/03-diagnose-test-failure-b4f514a956a92d85
2 parents 269eb4a + 07d73a0 commit 2027ba8

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

skills/rig/rig.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,45 @@ export type InferSchema<T> =
129129
unknown;
130130

131131
export const s = {
132+
/** Schema for a `string` value. Call as `s.string` or `s.string("description")`. */
132133
string: createTypedPrimitiveSchema<StringSchema>("string"),
134+
/** Schema for a `number` value. Call as `s.number` or `s.number("description")`. */
133135
number: createTypedPrimitiveSchema<NumberSchema>("number"),
136+
/** Schema for a `boolean` value. Call as `s.boolean` or `s.boolean("description")`. */
134137
boolean: createTypedPrimitiveSchema<BooleanSchema>("boolean"),
138+
/** Schema for an unconstrained JSON value. Serializes to an empty schema object. */
135139
unknown: createUnknownSchema(),
140+
/** Schema for a homogeneous array. `s.array(s.string)` → `string[]`. */
136141
array<Item extends Schema>(items: Item, description?: string): ArraySchema<Item> {
137142
return description === undefined ? markAsSchema({ type: "array", items }) : markAsSchema({ type: "array", items, description });
138143
},
144+
/** Schema for a fixed-shape object. Fields wrapped with `s.optional` are omitted from `required`. */
139145
object<Fields extends Record<string, Schema>>(properties: Fields, description?: string): ObjectSchema<Fields> {
140146
return description === undefined ? markAsSchema({ type: "object", properties }) : markAsSchema({ type: "object", properties, description });
141147
},
148+
/** Schema for a string-keyed map where every value shares the same schema. */
142149
record<Value extends Schema>(additionalProperties: Value, description?: string): RecordSchema<Value> {
143150
return description === undefined ? markAsSchema({ type: "object", additionalProperties }) : markAsSchema({ type: "object", additionalProperties, description });
144151
},
152+
/**
153+
* Schema for a closed set of literal values.
154+
*
155+
* @example
156+
* s.enum("low", "medium", "high")
157+
* s.enum(["low", "medium", "high"], "Risk level")
158+
*/
145159
enum: createEnumSchema,
160+
/**
161+
* Marks a schema field as optional so it is excluded from the `required` array
162+
* in the serialized JSON Schema and may be `undefined` in the inferred TypeScript type.
163+
*
164+
* @example
165+
* s.object({ file: s.optional(s.string) })
166+
*/
146167
optional<Inner extends Schema>(schema: Inner, description?: string): OptionalSchema<Inner> {
147168
return markAsOptional(cloneSchema(schema, description));
148169
},
170+
/** Converts a rig `Schema` to a plain JSON Schema object. */
149171
toJsonSchema,
150172
};
151173

0 commit comments

Comments
 (0)