Module Chatoyant_schema.CodecSource

Typed JSON codecs that carry JSON Schema.

A codec is the small bridge Chatoyant needs for ergonomic tool definitions: one value knows how to describe JSON with schema, decode incoming JSON into an OCaml value, and encode an OCaml value back to JSON.

Sourcetype 'a t
Sourcetype ('record, 'value) field
Sourceval schema : 'a t -> Schema.field
Sourceval custom : schema:Schema.field -> encode:('a -> Chatoyant_runtime.Json.t) -> decode:(Chatoyant_runtime.Json.t -> ('a, string) result) -> 'a t

Build a codec from explicit schema/encoder/decoder pieces.

This is primarily the low-level hook used by generated code and custom integrations. Prefer the typed builders or chatoyant.ppx in application code.

Sourceval map_schema : (Schema.field -> Schema.field) -> 'a t -> 'a t

Return an equivalent codec with its schema transformed.

Sourceval to_json_schema : 'a t -> Chatoyant_runtime.Json.t
Sourceval encode : 'a t -> 'a -> Chatoyant_runtime.Json.t
Sourceval decode : 'a t -> Chatoyant_runtime.Json.t -> ('a, string) result
Sourceval decode_field : string -> 'a t -> Chatoyant_runtime.Json.t -> ('a, string) result

Decode a field from a JSON object, respecting optional codecs.

Sourceval json : ?description:string -> unit -> Chatoyant_runtime.Json.t t
Sourceval string : ?description:string -> unit -> string t
Sourceval float : ?description:string -> unit -> float t
Sourceval int : ?description:string -> unit -> int t
Sourceval bool : ?description:string -> unit -> bool t
Sourceval string_enum : ?description:string -> string list -> string t
Sourceval array : ?description:string -> 'a t -> 'a list t
Sourceval optional : 'a t -> 'a option t
Sourceval field : string -> 'value t -> get:('record -> 'value) -> ('record, 'value) field
Sourceval object1 : ?description:string -> ('record, 'a) field -> ('a -> 'record) -> 'record t
Sourceval object2 : ?description:string -> ('record, 'a) field -> ('record, 'b) field -> ('a -> 'b -> 'record) -> 'record t
Sourceval object3 : ?description:string -> ('record, 'a) field -> ('record, 'b) field -> ('record, 'c) field -> ('a -> 'b -> 'c -> 'record) -> 'record t
Sourceval object4 : ?description:string -> ('record, 'a) field -> ('record, 'b) field -> ('record, 'c) field -> ('record, 'd) field -> ('a -> 'b -> 'c -> 'd -> 'record) -> 'record t
Sourceval object5 : ?description:string -> ('record, 'a) field -> ('record, 'b) field -> ('record, 'c) field -> ('record, 'd) field -> ('record, 'e) field -> ('a -> 'b -> 'c -> 'd -> 'e -> 'record) -> 'record t