⌂ Modules nupp nupp.serde nupp.serde
nupp.serde separates logical data from its physical representation.
Schema is an immutable logical graph. Binding<T> joins that graph to a Nupp record, fixed-layout struct, or indexed dynamic value. JSON is the first prepared codec; the same schema remains available to XML, CBOR, and custom codecs.
Run-time clients build the same immutable graph and use dense dynamic slots:
Module contents Types Type Kind Description Bindinginterface A checked physical representation of a schema as T. DynamicBindinginterface A binding that constructs dense run-time values. DynamicValuerecord An indexed value owned by a dynamic binding. JsonCodecrecord A JSON codec that lazily prepares bindings. JsonProfilerecord Immutable JSON wire-policy identity. Kindtype Memberrecord One structure member with a stable dense index. MetadataKeyinterface A typed identity for format-neutral schema metadata. Preparedinterface A prepared JSON traversal for one binding and profile. PreparedDebuginterface A prepared schema-driven Debug formatter. Schemarecord One immutable logical schema node. SchemaBuilderrecord Incrementally constructs and then freezes a run-time structure schema. Serializableinterface Marker claimed by @derive(nupp.derive.Serde).
Functions Function Kind Description bindingOffunction Retrieves the binding registered by @derive(nupp.derive.Serde). dynamicfunction Creates the indexed dynamic binding for a frozen schema. jsonfunction Creates an immutable-profile JSON codec. keyfunction Declares a named key whose value type is fixed by the binding that persists it. listfunction Creates an immutable list node. loadStorefunction Decodes plain values written by saveStore back into a store. mapfunction Creates an immutable map node. metadataKeyfunction Creates a typed schema metadata identity. offunction optionalfunction Creates an immutable optional node. prepareDebugfunction Prepares and memoizes Debug formatting for a binding. saveStorefunction Encodes every occupied key of a store into plain values under its name.
Values
Types
Bindinginterface
A checked physical representation of a schema as T.
Type parameters
Methods
schema
schema : function ( self ) : Schema
Arguments
Returns
extension
Arguments Name Type Description ?self keyany
Returns
DynamicBindinginterface
A binding that constructs dense run-time values.
Methods
newValue
Arguments
Returns
DynamicValuerecord
An indexed value owned by a dynamic binding.
Methods
get
Reads a resolved member.
Arguments
Returns
Raises
get
Reads a member by logical name.
Arguments
Returns
set
Sets a resolved member after checking its schema identity.
Arguments
Returns
Raises
JsonCodecrecord
record JsonCodec
readonly profile : JsonProfile
function prepare < T > ( self , binding : Binding < T > ) : Prepared < T > end
function encode < T > ( self , binding : Binding < T > , value : T ) : string end
function write < T > ( self , binding : Binding < T > , value : T , exclusive out : Buffer ) : nil end
function write < T > ( self , binding : Binding < T > , value : T , exclusive out : Writer ) : nil end
function decode < T > ( self , binding : Binding < T > , text : string ) : ( T ? , string ? ) end
function decodeBuffer < T > ( self , binding : Binding < T > , exclusive input : Buffer ) : ( T ? , string ? ) end
end
A JSON codec that lazily prepares bindings.
Methods
prepare
Prepares and memoizes a fused traversal.
Arguments
Returns
write
write : function write < T > ( self , binding : Binding < T > , value : T , exclusive out : Buffer ) : nil
Appends one complete encoded root to caller-owned storage in one chunk.
Arguments Name Type Description selfany bindingBinding < T > valueT exclusive outBuffer
Returns
write
write : function write < T > ( self , binding : Binding < T > , value : T , exclusive out : Writer ) : nil
Streams one prepared value at the writer's current value position.
Arguments Name Type Description selfany bindingBinding < T > valueT exclusive outWriter
Returns
decodeBuffer
decodeBuffer : function decodeBuffer < T > ( self , binding : Binding < T > , exclusive input : Buffer ) : T ? , string ?
Decodes from caller-owned storage without materializing a final string.
Arguments Name Type Description selfany bindingBinding < T > exclusive inputBuffer
Returns
Fields
JsonProfilerecord
Immutable JSON wire-policy identity.
Fields
unknownMembers
unknownMembers : "reject" | "ignore"
Kindtype
type Kind = "unit"
| "null"
| "boolean"
| "integer"
| "unsigned"
| "number"
| "decimal"
| "string"
| "bytes"
| "timestamp"
| "optional"
| "list"
| "map"
| "structure"
| "tuple"
| "union"
| "stringEnum"
| "integerEnum"
| "document"
Memberrecord
One structure member with a stable dense index.
Methods
Fields
Preparedinterface
A prepared JSON traversal for one binding and profile.
The recursive prepared traversal handles structures, lists, string-keyed maps, optionals, scalar constraints, defaults, literals, and document members.
Type parameters
Methods
encode
Arguments Name Type Description ?self valueT
Returns
write
write : function ( self , value : T , exclusive out : Buffer ) : nil & function ( self , value : T , exclusive out : Writer ) : nil
Appends one encoded root through reserved caller-owned storage.
The prepared traversal writes one complete encoded value.
Arguments Name Type Description ?self valueT exclusive outBuffer
Returns
decode
Arguments Name Type Description ?self textstring
Returns
decodeBuffer
decodeBuffer : function ( self , exclusive input : Buffer ) : ( T ? , string ? )
Decodes a value held in caller-owned storage.
Arguments Name Type Description ?self exclusive inputBuffer
Returns
PreparedDebuginterface
sealed interface PreparedDebug < T >
format : function ( self , value : T ) : string
write : function ( self , value : T , exclusive out : Buffer ) : nil
end
A prepared schema-driven Debug formatter.
Type parameters
Methods
write
write : function ( self , value : T , exclusive out : Buffer ) : nil
Arguments Name Type Description ?self valueT exclusive outBuffer
Returns
Schemarecord
One immutable logical schema node.
Methods
extension
Answers a lazily computed typed extension.
Arguments
Returns
member
Finds a structure member by its logical name.
Arguments
Returns
element
element : function element ( self ) : Schema ?
Answers the element schema of an optional or list node.
Arguments Name Type Description selfany
Returns
key
Answers the key schema of a map node.
Arguments Name Type Description selfany
Returns
value
Answers the value schema of a map node.
Arguments Name Type Description selfany
Returns
expectMember
Finds a member or raises when it is absent.
Arguments
Returns
Raises
Fields
SchemaBuilderrecord
record SchemaBuilder
constructor ( self ) end
function structure ( self , name : string ) : SchemaBuilder end
function required ( self , name : string , target : Schema ) : SchemaBuilder end
function optional ( self , name : string , target : Schema ) : SchemaBuilder end
function defaulted ( self , name : string , target : Schema , value : any ) : SchemaBuilder end
function metadata < T > ( self , key : MetadataKey < T > , value : T ) : SchemaBuilder end
function memberMetadata < T > ( self , name : string , key : MetadataKey < T > , value : T ) : SchemaBuilder end
function freeze ( self ) : Schema end
end
Incrementally constructs and then freezes a run-time structure schema.
Methods
constructor
constructor : function constructor ( self )
Arguments Name Type Description selfany
structure
Starts a named structure.
Arguments
Returns
Raises
required
Adds a required member.
Arguments
Returns
optional
Adds an optional member.
Arguments
Returns
defaulted
Adds a member with a default.
Arguments
Returns
freeze
freeze : function freeze ( self ) : Schema
Freezes and answers the immutable schema.
Arguments Name Type Description selfany
Returns
Raises
Serializableinterface
interface Serializable
end
Marker claimed by @derive(nupp.derive.Serde).
Serialization remains a property of a Binding<T>, not an instance method. The empty contract lets derive advertise checked participation without making values carry a codec API.
Functions
bindingOffunction
local function bindingOf ( type : any ) : any
Retrieves the binding registered by @derive(nupp.derive.Serde).
Arguments Name Type Description typeany
Returns
Raises
dynamicfunction
Creates the indexed dynamic binding for a frozen schema.
Arguments Name Type Description schemaSchema
Returns
Raises
jsonfunction
Creates an immutable-profile JSON codec.
fieldNames, when supplied, runs only during preparation. The fused traversal sees the resulting immutable wire names.
Arguments Name Type Description optionsany ?
Returns
Raises
keyfunction
Declares a named key whose value type is fixed by the binding that persists it.
The key is registered as nupp.store.newKey registers one, so the name is opaque and unique, and the binding is retained so saveStore and loadStore can carry the value under that name.
Type parameters
Arguments Name Type Description namestring the opaque name to register
bindingBinding < T > the binding that encodes and decodes the value
Returns Type Description store . Key < T > the key
Raises
listfunction
Creates an immutable list node.
Arguments Name Type Description targetSchema
Returns
loadStorefunction
Decodes plain values written by saveStore back into a store.
Each name is looked up in this runtime state's registry and its value is decoded through the binding that key was declared with, so a value is checked against the schema this program gave the name. Keys the saved table does not mention are left as they are.
Arguments Name Type Description exclusive valuestore . Store the store to write
saved{ [ string ] : any } the table saveStore returned, or one decoded from a document
Returns Type Description nil nothing
Raises
mapfunction
Creates an immutable map node.
Arguments
Returns
Raises
offunction
function of < T > ( type : Type < T > ) : Binding < T >
Type parameters
Arguments Name Type Description typeType < T >
Returns
optionalfunction
Creates an immutable optional node.
Arguments Name Type Description targetSchema
Returns
prepareDebugfunction
Prepares and memoizes Debug formatting for a binding.
Type parameters
Arguments Name Type Description bindingBinding < T >
Returns
saveStorefunction
Encodes every occupied key of a store into plain values under its name.
The values are the documents a JSON codec with default field names writes, so a saved store rides inside whatever document the application encodes.
Arguments Name Type Description borrows valuestore . Store the store to save
Returns Type Description { [ string ] : any } a fresh table from name to plain value
Raises
Values
debugSkipvariable
Standard Debug policy metadata shared by derived and dynamic schemas.
unitvariable
Format-neutral scalar schema singletons.
← Previous nupp.runtime.workersprovider Next → nupp.services