moonrockz/openrpc/json
Types
Code
pub(all) enum Code {
Syntax
DuplicateKey
LimitExceeded
InvalidNumber
InvalidReference
UnresolvedReference
WrongType
MissingField
UnsupportedVersion
UnsupportedDialect
UnsupportedCheck
InvalidSchema
ParameterOrder
MissingBaseUri
UnavailableResource
ConflictingIdentifier
ReferenceCycle
DuplicateName
DuplicateErrorCode
UnknownMethod
UnknownField
InvalidValue
StaleNode
} derive(Eq, @moonbitlang/core/debug.Debug)Code::equal
fn Code::equal(Code, Code) -> BoolCode::not_equal
fn Code::not_equal(x : Code, y : Code) -> BoolCode::to_repr
fn Code::to_repr(Code) -> @moonbitlang/core/debug.ReprCstDocument
pub struct CstDocument {
source : String
source_id : String?
nodes : Array[Node]
limits : Limits
} derive(@moonbitlang/core/debug.Debug)CstDocument::limits
fn CstDocument::limits(self : CstDocument) -> LimitsCstDocument::lower
fn CstDocument::lower(self : CstDocument) -> Result[Value, Array[Diagnostic]]CstDocument::node_at
fn CstDocument::node_at(self : CstDocument, path : Array[String]) -> NodeId?The first node at a structured path. Duplicate names have several nodes;
SourceMap::locations lists them all.
CstDocument::node_id
fn CstDocument::node_id(self : CstDocument, index : Int) -> NodeId?CstDocument::nodes
fn CstDocument::nodes(self : CstDocument) -> Array[Node]CstDocument::path
fn CstDocument::path(self : CstDocument, index : Int) -> Array[String]?CstDocument::replace_value
fn CstDocument::replace_value(self : CstDocument, node : NodeId, value : Value, limits? : Limits) -> Result[CstDocument, Diagnostic]Replace the value at node with the compact encoding of value and parse
the result. Every code unit outside the value's span is kept, including a
member's key and the whitespace around it. The original CST is unchanged.
CstDocument::reproduce
fn CstDocument::reproduce(self : CstDocument) -> StringCstDocument::slice
fn CstDocument::slice(self : CstDocument, span : Span) -> String?CstDocument::source_id
fn CstDocument::source_id(self : CstDocument) -> String?CstDocument::source_map
fn CstDocument::source_map(self : CstDocument) -> SourceMapCstDocument::span_at
fn CstDocument::span_at(self : CstDocument, path : Array[String]) -> Span?CstDocument::to_repr
fn CstDocument::to_repr(CstDocument) -> @moonbitlang/core/debug.ReprCstDocument::tokens
fn CstDocument::tokens(self : CstDocument) -> Array[Token]Tokenize the already-checked source, including every trivia occurrence.
Diagnostic
pub struct Diagnostic {
code : Code
message : String
path : Array[String]
span : Span?
related : Array[Span]
} derive(@moonbitlang/core/debug.Debug)Diagnostic::code
fn Diagnostic::code(self : Diagnostic) -> CodeDiagnostic::message
fn Diagnostic::message(self : Diagnostic) -> StringDiagnostic::new
fn Diagnostic::new(code : Code, message : String, path? : Array[String], span? : Span?, related? : Array[Span]) -> DiagnosticDiagnostic::path
fn Diagnostic::path(self : Diagnostic) -> Array[String]Diagnostic::related
fn Diagnostic::related(self : Diagnostic) -> Array[Span]Diagnostic::span
fn Diagnostic::span(self : Diagnostic) -> Span?Diagnostic::to_repr
fn Diagnostic::to_repr(Diagnostic) -> @moonbitlang/core/debug.ReprFormat
pub(all) enum Format {
Compact
Pretty
} derive(Eq, @moonbitlang/core/debug.Debug)Output layout. Compact is canonical; Pretty adds two-space indentation
and changes nothing else.
Format::equal
fn Format::equal(Format, Format) -> BoolFormat::not_equal
fn Format::not_equal(x : Format, y : Format) -> BoolFormat::to_repr
fn Format::to_repr(Format) -> @moonbitlang/core/debug.ReprKind
pub(all) enum Kind {
Null
Boolean(Bool)
String(String)
Numeric(Number)
Array(Array[Value])
Object(Array[(String, Value)])
} derive(@moonbitlang/core/debug.Debug)Kind::to_repr
fn Kind::to_repr(Kind) -> @moonbitlang/core/debug.ReprLimits
pub struct Limits {
max_depth : Int
max_nodes : Int
max_source : Int
max_number : Int
max_findings : Int
} derive(@moonbitlang/core/debug.Debug)Limits::max_depth
fn Limits::max_depth(self : Limits) -> IntLimits::max_findings
fn Limits::max_findings(self : Limits) -> IntLimits::max_nodes
fn Limits::max_nodes(self : Limits) -> IntLimits::max_number
fn Limits::max_number(self : Limits) -> IntLimits::max_source
fn Limits::max_source(self : Limits) -> IntLimits::new
fn Limits::new(max_depth? : Int, max_nodes? : Int, max_source? : Int, max_number? : Int, max_findings? : Int) -> LimitsLimits::to_repr
fn Limits::to_repr(Limits) -> @moonbitlang/core/debug.ReprLimits::unlimited
fn Limits::unlimited() -> LimitsRemove policy bounds within the maximum representable String/Array sizes. This does not guarantee available host memory.
Location
pub struct Location {
source_id : String?
node_index : Int
value_span : Span
key_span : Span?
// private fields
} derive(@moonbitlang/core/debug.Debug)Location::key_span
fn Location::key_span(self : Location) -> Span?Location::node
fn Location::node(self : Location) -> NodeIdThe node as a handle that CstDocument::replace_value accepts.
Location::node_index
fn Location::node_index(self : Location) -> IntIndex into the owning CST only. It is not stable across parses or edits.
Location::source_id
fn Location::source_id(self : Location) -> String?Location::to_repr
fn Location::to_repr(Location) -> @moonbitlang/core/debug.ReprLocation::value_span
fn Location::value_span(self : Location) -> SpanNode
pub struct Node {
kind : NodeKind
span : Span
key : String?
key_span : Span?
children : Array[Int]
scalar : Value?
parent : Int?
ordinal : Int
} derive(@moonbitlang/core/debug.Debug)Node::children
fn Node::children(self : Node) -> Array[Int]Node::key
fn Node::key(self : Node) -> String?Node::key_span
fn Node::key_span(self : Node) -> Span?Node::kind
fn Node::kind(self : Node) -> NodeKindNode::span
fn Node::span(self : Node) -> SpanNode::to_repr
fn Node::to_repr(Node) -> @moonbitlang/core/debug.ReprNodeId
pub struct NodeId {
// private fields
}A handle to one CST node. It is valid only for a CST with exactly the same source text as the parse that produced it.
NodeId::index
fn NodeId::index(self : NodeId) -> IntNodeId::to_repr
fn NodeId::to_repr(self : NodeId) -> @moonbitlang/core/debug.Reprimpl Debug for NodeId
Debug::to_repr
fn to_repr(self : NodeId) -> @moonbitlang/core/debug.ReprNodeKind
pub(all) enum NodeKind {
Scalar
ArrayNode
ObjectNode
} derive(Eq, @moonbitlang/core/debug.Debug)NodeKind::equal
fn NodeKind::equal(NodeKind, NodeKind) -> BoolNodeKind::not_equal
fn NodeKind::not_equal(x : NodeKind, y : NodeKind) -> BoolNodeKind::to_repr
fn NodeKind::to_repr(NodeKind) -> @moonbitlang/core/debug.ReprNumber
pub struct Number {
token : String
} derive(Eq, @moonbitlang/core/debug.Debug)Number::equal
fn Number::equal(Number, Number) -> BoolNumber::is_integer
fn Number::is_integer(self : Number) -> BoolNumber::not_equal
fn Number::not_equal(x : Number, y : Number) -> BoolNumber::numeric_compare
fn Number::numeric_compare(self : Number, other : Number) -> IntCompare mathematical values without converting to binary floating point.
Number::numeric_equal
fn Number::numeric_equal(self : Number, other : Number) -> BoolNumber::numeric_key
fn Number::numeric_key(self : Number) -> StringA key that is equal exactly when the numbers are numerically equal, for hashing many values without pairwise comparison.
Number::parse
fn Number::parse(token : String) -> Result[Number, Diagnostic]Number::to_repr
fn Number::to_repr(Number) -> @moonbitlang/core/debug.ReprNumber::token
fn Number::token(self : Number) -> StringPosition
pub struct Position {
line : Int
column : Int
} derive(Eq, @moonbitlang/core/debug.Debug)Position::column
fn Position::column(self : Position) -> IntPosition::equal
fn Position::equal(Position, Position) -> BoolPosition::line
fn Position::line(self : Position) -> IntPosition::not_equal
fn Position::not_equal(x : Position, y : Position) -> BoolPosition::to_repr
fn Position::to_repr(Position) -> @moonbitlang/core/debug.ReprSourceMap
pub struct SourceMap {
cst : CstDocument
line_starts : Array[Int]
} derive(@moonbitlang/core/debug.Debug)SourceMap::locations
fn SourceMap::locations(self : SourceMap, path : Array[String]) -> Array[Location]Return all occurrences. Duplicate object names have no implicit winner.
SourceMap::position
fn SourceMap::position(self : SourceMap, offset : Int) -> Position?SourceMap::to_repr
fn SourceMap::to_repr(SourceMap) -> @moonbitlang/core/debug.ReprSpan
pub struct Span {
start : Int
end : Int
} derive(Eq, @moonbitlang/core/debug.Debug)Span::end
fn Span::end(self : Span) -> IntSpan::equal
fn Span::equal(Span, Span) -> BoolSpan::new
fn Span::new(start : Int, end : Int) -> Span?Span::not_equal
fn Span::not_equal(x : Span, y : Span) -> BoolSpan::start
fn Span::start(self : Span) -> IntSpan::to_repr
fn Span::to_repr(Span) -> @moonbitlang/core/debug.ReprToken
pub struct Token {
kind : TokenKind
span : Span
text : String
} derive(@moonbitlang/core/debug.Debug)Token::kind
fn Token::kind(self : Token) -> TokenKindToken::span
fn Token::span(self : Token) -> SpanToken::text
fn Token::text(self : Token) -> StringToken::to_repr
fn Token::to_repr(Token) -> @moonbitlang/core/debug.ReprTokenKind
pub(all) enum TokenKind {
Whitespace
OpenObject
CloseObject
OpenArray
CloseArray
Colon
Comma
StringToken
NumberToken
TrueToken
FalseToken
NullToken
} derive(Eq, @moonbitlang/core/debug.Debug)TokenKind::equal
fn TokenKind::equal(TokenKind, TokenKind) -> BoolTokenKind::not_equal
fn TokenKind::not_equal(x : TokenKind, y : TokenKind) -> BoolTokenKind::to_repr
fn TokenKind::to_repr(TokenKind) -> @moonbitlang/core/debug.ReprValue
pub struct Value {
// private fields
} derive(@moonbitlang/core/debug.Debug)Value::array
fn Value::array(items : Array[Value]) -> ValueValue::array_item
fn Value::array_item(self : Value, index : Int) -> Value?Return an immutable array child, or None for a non-array or missing index.
Value::array_length
fn Value::array_length(self : Value) -> Int?Inspect array size without creating a copied collection view.
Value::boolean
fn Value::boolean(value : Bool) -> ValueValue::equals
fn Value::equals(self : Value, other : Value, numeric? : Bool, limits? : Limits) -> Result[Bool, Diagnostic]Compare decoded JSON values. Object member order is insignificant.
Numeric token spelling is significant unless numeric is selected.
Value::get
fn Value::get(self : Value, name : String) -> Value?Value::kind
fn Value::kind(self : Value) -> KindValue::null
fn Value::null() -> ValueValue::number
fn Value::number(value : Number) -> ValueValue::object
fn Value::object(fields : Array[(String, Value)]) -> Result[Value, Diagnostic]Value::string
fn Value::string(value : String) -> ValueValue::text
fn Value::text(self : Value) -> String?Value::to_repr
fn Value::to_repr(Value) -> @moonbitlang/core/debug.ReprValues
from_core_json
fn from_core_json(value : Json, limits? : Limits) -> Result[Value, Diagnostic]Capture the representation the caller's core Json still has. Missing original numeric digits cannot be recovered.
parse
fn parse(source : String, source_id? : String?, limits? : Limits) -> Result[CstDocument, Diagnostic]to_core_json
fn to_core_json(value : Value, limits? : Limits) -> Result[Json, Diagnostic]Set core numeric repr explicitly. Core arithmetic/equality still use Double.
write
fn write(value : Value, format? : Format, limits? : Limits) -> Result[String, Diagnostic]Deterministic JSON text: object keys by UTF-16 code units, exact number
tokens, array order kept, no final newline. Pretty only adds layout.