Keel: Neutral Contracts for Racket Desktop Runtimes
| (require keel) | package: keel |
Keel defines a transport-neutral value codec, structured error shape, schema vocabulary, and lifecycle vocabulary. It deliberately does not define a renderer or protocol frame.
1 Values
procedure
(app-value? value) → boolean?
value : any/c
procedure
(encode-app-value value) → bytes?
value : app-value?
procedure
(decode-app-value encoded) → app-value?
encoded : bytes?
2 Structured errors
procedure
(app-error? value) → boolean?
value : any/c
procedure
(make-app-error code message [data]) → app-error?
code : app-error-code? message : string? data : app-value? = app-null
procedure
(app-error-code? value) → boolean?
value : any/c
procedure
(app-error-code error) → string?
error : app-error?
procedure
(app-error-message error) → string?
error : app-error?
procedure
(app-error-data error) → app-value?
error : app-error?
3 Schemas
A schema describes application messages without selecting their transport. Rivet can map a command to an RVT1 RPC while Glaze maps it to a GLZ1 invoke.
struct
(struct scalar-type (name))
name : symbol?
struct
element : schema-type?
struct
value : schema-type?
struct
(struct optional-type (element))
element : schema-type?
struct
(struct reference-type (name))
name : string?
value
value
value
value
value
value
value
value
value
struct
(struct schema-field (name type))
name : string? type : schema-type?
struct
(struct schema-record (name fields))
name : string? fields : (listof schema-field?)
struct
(struct schema-enum (name cases))
name : string? cases : (listof string?)
struct
(struct schema-parameter (name type))
name : string? type : schema-type?
struct
(struct schema-command (name parameters result error-codes))
name : string? parameters : (listof schema-parameter?) result : schema-type? error-codes : (listof app-error-code?)
struct
(struct schema-event (name type))
name : string? type : schema-type?
struct
(struct schema-state (name type))
name : string? type : schema-type?
procedure
(make-app-schema id revision [ #:records records #:enums enums #:commands commands #:events events #:states states]) → app-schema? id : string? revision : exact-nonnegative-integer? records : list? = null enums : list? = null commands : list? = null events : list? = null states : list? = null
procedure
(app-schema? value) → boolean?
value : any/c
procedure
(app-schema-id schema) → string?
schema : app-schema?
procedure
(app-schema-revision schema) → exact-nonnegative-integer?
schema : app-schema?
procedure
(app-schema-records schema) → (listof schema-record?)
schema : app-schema?
procedure
(app-schema-enums schema) → (listof schema-enum?)
schema : app-schema?
procedure
(app-schema-commands schema) → (listof schema-command?)
schema : app-schema?
procedure
(app-schema-events schema) → (listof schema-event?)
schema : app-schema?
procedure
(app-schema-states schema) → (listof schema-state?)
schema : app-schema?
procedure
(schema-type? value) → boolean?
value : any/c
procedure
(schema-name? value) → boolean?
value : any/c
procedure
(schema-type->app-value type) → app-value?
type : schema-type?
procedure
(app-schema->app-value schema) → app-value?
schema : app-schema?
procedure
(encode-app-schema schema) → bytes?
schema : app-schema?
The scalar descriptors are Null, Bool, Int64, Float64, String, Bytes, Value, Error, and Unit. Compound descriptors use list-type, map-type, optional-type, and reference-type. Definitions use schema-field, schema-record, schema-enum, schema-parameter, schema-command, schema-event, and schema-state.
4 Schema compatibility
Two schema revisions are comparable without a transport. A change is 'breaking when an existing peer can observe a different value, name, type, or closed case set, and 'compatible otherwise. Revision numbers are not interpreted: callers decide whether a revision replaces, supersedes, or accompanies the old one.
struct
(struct schema-change (severity path detail))
severity : (or/c 'breaking 'compatible) path : string? detail : string?
procedure
(app-schema-changes old new) → (listof schema-change?)
old : app-schema? new : app-schema?
procedure
(schema-compatible? old new) → boolean?
old : app-schema? new : app-schema?
5 Lifecycle
value
lifecycle-states : (listof symbol?)
value
procedure
(lifecycle-state? value) → boolean?
value : any/c
procedure
(lifecycle-terminal-state? value) → boolean?
value : any/c
procedure
(lifecycle-transition? from to) → boolean?
from : lifecycle-state? to : lifecycle-state?
value
request-terminal-outcomes : (listof symbol?)
procedure
(request-terminal-outcome? value) → boolean?
value : any/c