npm install @karma.run/sdk` or `yarn add @karma.run/sdk
There are 21 classes that implement the
Value interface. They are the JS/TS representation of karma.data values:
Each Value class has a corresponding constructor on the package top-level, having the same name as the class but with a lower-case first letter. For example a
Uint64 can be constructed calling the constructor function named
As a special case, because
null is a reserved keyword in JS, we export a package-level name
nil assigned to an instance of
val.Null for convenience.
All Value classes implement two methods:
As you may know, a call to
JSON.stringify(o) with an object
o that has a
toJSON() method will first call that method to delegate serialization.
This method transforms a Value object into the JSON-structure expected by karma.data's
toDataConstructor returns a
DataConstructor expression, which can be wrapped in a call to
xpr.data to embed static data in an expression.
There are hundreds of expression classes with corresponding convenience constructors, just as with Values. These classes all extend the abstract class
Expression. For example, there is an
All class, which can be constructed using the
all convenience constructor.
In addition, expressions can be constructed by chaining. Every expression has methods corresponding to the constructors with a given first expresison argument. For example
xpr.tag("_tag").all() is equivalent to
All Expression classes implement the method
toValue() that returns a Value object. This is the value-representation of an expression, which can be JSON-encoded to send over the wire in karma.data's
There are 26 Model classes:
All Model classes implement two methods:
decode(json : any) and
toValue(), both returning Value objects.
This method takes a wire-representation of karma.data's
json codec and converts it into a Value objects, interpreting the data according to the given Model.
This method transforms a Model object into its' Value object representation. From there, it can be converted into a data constructor or JSON.