type

LibNamespace

@Js
const mixin LibNamespace

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 LibRepo.createNamespace.

methods

base

Return base namespace if this namespace is an overlay.

compileData

Compile a Xeto data file into an in-memory value.

compileDicts

Convenience for compileData but always returns data as list of dicts.

compileLib

Compile Xeto source code into a temp library.

digest

Base64 digest for this namespace based on its lib versions

eachInstance

Iterate all the instances

eachType

Iterate all the top-level types in all the libs.

fits

Return if the given instance fits the spec via structural typing.

hasLib

Return if this namespace contains the given lib name.

instance

Get or load instance by the given qualified name If the instance's lib is not loaded, it is loaded synchronously.

instantiate

Create default instance for the given spec.

isAllLoaded

Return true if the every library in this namespace has been loaded (successfully or unsuccessfully).

isOverlay

Return true if this an overlay namespace overlaid on base.

lib

Get the given library by name synchronously.

libAsync

Get or load library asynchronously by the given dotted name.

libErr

Exception for a library with lib status of err, or null otherwise.

libListAsync

Get or load list of libraries asynchronously by the given dotted names.

libStatus

Return load status for the given library name

libs

List all libraries.

libsAllAsync

Load all libraries asynchronosly.

spec

Get or load spec by the given qualified name

specOf

Spec for Fantom Type or the typeof given object

type

Get or load type by the given qualified name.

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

base

abstract LibNamespace? base()

Return base namespace if this namespace is an overlay.

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.

compileLib

abstract Lib compileLib(Str src, Dict? opts := null)

Compile Xeto source code into a temp library. All dependencies are resolved against this namespace. Raise exception if there are any syntax or semantic errors.

digest

abstract Str digest()

Base64 digest for this namespace based on its lib versions

eachInstance

abstract Void eachInstance(|Dict| f)

Iterate all the instances

eachType

abstract Void eachType(|Spec| f)

Iterate all the top-level types in all the libs. Raise exception is not fully loaded.

fits

abstract Bool fits(XetoContext cx, Obj? val, Spec spec, Dict? opts := null)

Return if the given instance fits the spec via structural typing.

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.

instance

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

Get or load instance by the given qualified name If the instance's lib is not loaded, it is loaded synchronously.

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

isAllLoaded

abstract Bool isAllLoaded()

Return true if the every library in this namespace has been loaded (successfully or unsuccessfully). This method returns false is any libs have a load status of notLoaded. Many operations require a namespace to be fully loaded.

isOverlay

abstract Bool isOverlay()

Return true if this an overlay namespace overlaid on base.

lib

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

Get the given library by name synchronously. If this is a Java environment, then the library will be compiled on its first access. If the library cannot be compiled then an exception is always raised regardless of checked flag. If this is a JS environment then the library must already have been loaded, otherwise raise exception regardless of checked flag. The checked flag only returns null if the library is not defined by this namespace. Use libAsync to load a library in JS environment.

libAsync

abstract Void libAsync(Str name, |Err?,Lib?| f)

Get or load library asynchronously by the given dotted name. This method automatically also loads the dependency chain. Once loaded then invoke callback with library or err.

libErr

abstract Err? libErr(Str name)

Exception for a library with lib status of err, or null otherwise. Raise exception is library not included in this namespace.

libListAsync

abstract Void libListAsync(Str[] names, |Err?,Lib[]?| f)

Get or load list of libraries asynchronously by the given dotted names. This method automatically also loads the dependency chain. Once loaded then invoke callback with libraries or err. If a lib cannot be loaded then it is excluded from the callback list (so its possible the results list is not the same size as the names list).

libStatus

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

Return load status for the given library name:

  • notLoaded: library is included but has not been loaded yet
  • 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. On first call, this will force all libraries to be loaded synchronously. Any libs which cannot be compiled will log an error and be excluded from this list. If isAllLoaded is true then this call can also be in JS environments, otherwise you must use the libsAllAsync call to fully load all libraries into memory.

libsAllAsync

abstract Void libsAllAsync(|Err?,Lib[]?| f)

Load all libraries asynchronosly. Once this operation completes successfully the isAllLoaded method will return true and the libs method may be used even in JS environments. Note that an error is reported only if the entire load failed. Individual libs which cannot be loaded will logged on server, and be excluded from the final libs list.

spec

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

Get or load spec by the given qualified name:

  • type: "foo.bar::Baz"
  • global: "foo.bar::baz"
  • slot: "foo.bar::Baz.qux" If the spec's lib is not loaded, it is loaded synchronously.

specOf

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

Spec for Fantom Type or the typeof given object

type

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

Get or load type by the given qualified name. If the type's lib is not loaded, it is loaded synchronously.

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.