types
Pre-baked type aliases that combine @validate(...) and @jsonSchema(...) for the most common string-shaped opaque types. Use them in place of plain string whenever the value must conform to one of these formats:
import { Email } from "std::types"
def main() {
const e: Email! = "user@example.com" // validated at runtime
}Aliases here only carry annotations — they are still plain string from TypeScript's perspective. Validation runs on ! sites; structured-output LLM calls get the JSON Schema format hint via .meta(...).
Types
Email
A syntactically valid email address.
/** A syntactically valid email address. */
@validate(isEmail)
@jsonSchema({
...emailFormat
})
export type Email = stringValidators: isEmail
JSON Schema metadata:
{
...emailFormat
}(source)
URLString
An http:// or https:// URL. (Named URLString so it does not shadow JavaScript's global URL constructor.)
/** An http:// or https:// URL. (Named `URLString` so it does not shadow
JavaScript's global `URL` constructor.) */
@validate(isUrl)
@jsonSchema({
...urlFormat
})
export type URLString = stringValidators: isUrl
JSON Schema metadata:
{
...urlFormat
}(source)
UUIDString
A canonical 8-4-4-4-12 hex UUID string. (Named UUIDString for symmetry with URLString.)
/** A canonical 8-4-4-4-12 hex UUID string. (Named `UUIDString` for symmetry
with `URLString`.) */
@validate(isUuid)
@jsonSchema({
...uuidFormat
})
export type UUIDString = stringValidators: isUuid
JSON Schema metadata:
{
...uuidFormat
}(source)
NumberInRange
A number that must lie within the inclusive range [low, high]. Use as NumberInRange(0, 100) etc. — both bounds substitute into the @validate(...) and @jsonSchema(...) tags at the use site.
/** A number that must lie within the inclusive range `[low, high]`.
Use as `NumberInRange(0, 100)` etc. — both bounds substitute into the
`@validate(...)` and `@jsonSchema(...)` tags at the use site. */
@validate(min.partial(n: low), max.partial(n: high))
@jsonSchema({
minimum: low,
maximum: high
})
export type NumberInRange(low: number, high: number) = numberValidators: min.partial(n: low), max.partial(n: high)
JSON Schema metadata:
{
minimum: low,
maximum: high
}(source)
StringWithLength
A string whose length is in the inclusive range [min, max].
/** A string whose length is in the inclusive range `[min, max]`. */
@validate(minLength.partial(n: min), maxLength.partial(n: max))
@jsonSchema({
minLength: min,
maxLength: max
})
export type StringWithLength(min: number, max: number) = stringValidators: minLength.partial(n: min), maxLength.partial(n: max)
JSON Schema metadata:
{
minLength: min,
maxLength: max
}(source)
MatchesPattern
A string that matches the given regular expression pat.
/** A string that matches the given regular expression `pat`. */
@validate(matches.partial(pattern: pat))
@jsonSchema({
pattern: pat
})
export type MatchesPattern(pat: string) = stringValidators: matches.partial(pattern: pat)
JSON Schema metadata:
{
pattern: pat
}(source)
BoundedArray
An array whose length is in the inclusive range [min, max].
/** An array whose length is in the inclusive range `[min, max]`. */
@jsonSchema({
minItems: min,
maxItems: max
})
export type BoundedArray<T>(min: number, max: number) = T[]JSON Schema metadata:
{
minItems: min,
maxItems: max
}(source)