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 compileData but always returns data as list of dicts.

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 err, or null otherwise.

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 Type or the typeof given object

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 spec tag.

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

abstract Void eachInstance(|Dict| f)

Iterate all the instances in libs

eachSubtype

abstract Void eachSubtype(Spec base, |Spec| f)

Iterate all the direct subtypes of given type

eachType

abstract Void eachType(|Spec| f)

Iterate all the top-level types in libs.

eachTypeWhile

abstract Obj? eachTypeWhile(|Spec->Obj?| f)

Iterate all top-level types in libs until callback returns non-null.

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 points
  • ignoreRefs: marker to ignore if refs resolve to valid target
  • haystack: 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

abstract Bool hasLib(Str name)

Return if this namespace contains the given lib name. This is true if version will return non-null regardless of libStatus.

hasSubtypes

abstract Bool hasSubtypes(Spec base)

Return if given type has at least one direct subtype.

instance

abstract Dict? instance(Str qname, Bool checked := true)

Get an instance by the given qualified name

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 abstract
  • id: Ref tag to include in new instance
  • haystack: marker tag to use Haystack level data fidelity

lib

abstract Lib? lib(Str name, Bool checked := true)

Get the given library by name. If the library is not in the namesapce or could be compiled then raise an exception unless checked is false.

libErr

abstract Err? libErr(Str name, Bool checked := true)

Exception for a library with lib status of err, or null otherwise. Return null/exception if library not included

libStatus

abstract LibStatus? libStatus(Str name, Bool checked := true)

Return load status for the given library name:

  • ok: library is included and loaded successfully
  • err: 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

abstract Spec[] mixinsFor(Spec type)

Get all the mixins inherited into the given type. This operation can be expensive.

parseToDicts

abstract Dict[] parseToDicts(Str src, Dict? opts := null)

Parse one or more specs/instances to their AST representation as dicts Options:

  • libName: for internal qnames (default to proj)

spec

abstract Spec? spec(Str qname, Bool checked := true)

Get a spec by the given qualified name:

  • type/mixin: "foo.bar::Baz"
  • slot/global: "foo.bar::Baz.qux"

specOf

abstract Spec? specOf(Obj? val, Bool checked := true)

Spec for Fantom Type or the typeof given object

specx

abstract Spec specx(Spec type)

Compute the extended type spec by merging all meta and slots from mixins. This call can be quite expensive; so cache and reuse the result for your operation.

type

abstract Spec? type(Str qname, Bool checked := true)

Get a type spec by the given qualified name.

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.