type
Namespace
@Js
const mixin Namespace
Library namespace is a pinned manifest of specific library versions. Namespaces may lazily load their libs, in which case not all operations are supported. Create a new namespace via XetoEnv.createNamespace.
methods
| choice |
Return choice API for given spec. |
|---|---|
| compileData |
Compile a Xeto data file into an in-memory value. |
| compileDicts |
Convenience for |
| digest |
Base64 digest for this namespace based on its lib versions Note: this digest only changes when the libs and/or versions are modified. |
| eachInstance |
Iterate all the instances in libs |
| eachSubtype |
Iterate all the direct subtypes of given type |
| eachType |
Iterate all the top-level types in libs. |
| eachTypeWhile |
Iterate all top-level types in libs until callback returns non-null. |
| env |
Environment used to create this namespace |
| fits |
Return if the given instance fits the spec via structural typing. |
| funcs |
Get the effective map of all functions. |
| hasLib |
Return if this namespace contains the given lib name. |
| hasSubtypes |
Return if given type has at least one direct subtype. |
| instance |
Get an instance by the given qualified name |
| instantiate |
Create default instance for the given spec. |
| lib |
Get the given library by name. |
| libErr |
Exception for a library with lib status of |
| libStatus |
Return load status for the given library name |
| libs |
List all libraries. |
| metas |
Get the effective spec metadata slots. |
| mixinsFor |
Get all the mixins inherited into the given type. |
| parseToDicts |
Parse one or more specs/instances to their AST representation as dicts Options |
| spec |
Get a spec by the given qualified name |
| specOf |
Spec for Fantom |
| specx |
Compute the extended type spec by merging all meta and slots from mixins. |
| type |
Get a type spec by the given qualified name. |
| validate |
Validate a single value against a spec. |
| validateAll |
Validate a graph of records using their configured |
| version |
Lookup the version info for a library name in this namespace. |
| versions |
List the library name and versions in this namespace. |
| writeData |
Write instance data in Xeto text format to an output stream. |
Slot Details
choice
abstract SpecChoice choice(Spec spec)
Return choice API for given spec. Callers should prefer the slot over the type since the slot determines maybe and multi-choice flags. Raise exception if Spec.isChoice is false.
compileData
abstract Obj? compileData(Str src, Dict? opts := null)
Compile a Xeto data file into an in-memory value. All dependencies are resolved against this namespace. Raise exception if there are any syntax or semantic errors. If the file contains a scalar value or one dict, then it is returned as the value. If the file contains two or more dicts then return a Dict[] of the instances.
Options
- externRefs: marker to allow unresolved refs to compile
compileDicts
abstract Dict[] compileDicts(Str src, Dict? opts := null)
Convenience for compileData but always returns data as list of dicts. If the data is not a Dict nor list of Dicts, then raise an exception.
digest
abstract Str digest()
Base64 digest for this namespace based on its lib versions Note: this digest only changes when the libs and/or versions are modified. It is not a digest of the lib contents.
eachInstance
eachSubtype
eachType
eachTypeWhile
env
abstract XetoEnv env()
Environment used to create this namespace
fits
abstract Bool fits(Obj? val, Spec spec, Dict? opts := null)
Return if the given instance fits the spec via structural typing. Options:
graph: marker to also check graph of references such as required pointsignoreRefs: marker to ignore if refs resolve to valid targethaystack: marker tag to use Haystack level data fidelity
funcs
abstract SpecMap funcs()
Get the effective map of all functions. This is semantically equivalent to specx(Funcs).slots.
hasLib
hasSubtypes
instance
instantiate
abstract Obj? instantiate(Spec spec, Dict? opts := null)
Create default instance for the given spec. Raise exception if spec is abstract.
Options:
graph: marker tag to instantiate graph of recs (will auto-generate ids)abstract: marker to supress error if spec is abstractid: Ref tag to include in new instancehaystack: marker tag to use Haystack level data fidelity
lib
libErr
libStatus
abstract LibStatus? libStatus(Str name, Bool checked := true)
Return load status for the given library name:
ok: library is included and loaded successfullyerr: library is included but could not be loaded- null/exception if library not included
libs
abstract Lib[] libs()
List all libraries. Any libs which cannot be compiled are excluded.
metas
abstract SpecMap metas()
Get the effective spec metadata slots. This is semantically equivalent to specx(Spec).slots.
mixinsFor
parseToDicts
spec
specOf
specx
type
validate
abstract ValidateReport validate(Obj? val, Spec? spec := null, Dict? opts := null)
Validate a single value against a spec. If spec is null, then validate against specOf(val). Should be called within an XetoContext context to verify external refs.
validateAll
abstract ValidateReport validateAll(Dict[] subjects, Dict? opts := null)
Validate a graph of records using their configured spec tag. Should be called within an XetoContext context to verify external refs.
version
abstract LibVersion? version(Str name, Bool checked := true)
Lookup the version info for a library name in this namespace.
versions
abstract LibVersion[] versions()
List the library name and versions in this namespace.
writeData
abstract Void writeData(OutStream out, Obj val, Dict? opts := null)
Write instance data in Xeto text format to an output stream. If the value is a Dict[], then it is flattened in the output. Use compileData to read data from Xeto text format.