- Index
- »
- xeto
- »
- LibNamespace
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. |
---|---|
choice |
Return choice API for given spec. |
compileData |
Compile a Xeto data file into an in-memory value. |
compileDicts |
Convenience for |
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 in libs In remote namespace this only iterates loaded libs. |
eachType |
Iterate all the top-level types in 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 |
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 |
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 |
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. |
xmeta |
Lookup the extended meta for the given spec qname. |
xmetaEnum |
Lookup the extended meta for an enum spec. |
Slot Details
base
abstract LibNamespace? base()
Return base namespace if this namespace is an overlay.
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.
compileLib
digest
abstract Str digest()
Base64 digest for this namespace based on its lib versions
eachInstance
eachType
fits
abstract Bool fits(XetoContext cx, 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
hasLib
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
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
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
libErr
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 yetok
: 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. 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
specOf
type
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.
xmeta
abstract Dict? xmeta(Str qname, Bool checked := true)
Lookup the extended meta for the given spec qname. This is a merge of the spec's own meta along with any instance dicts in the namespace with a local id of "xmeta-{lib}-{spec}". Only libs currently loaded are considered for the result. If the spec is not defined then return null or raise an exception based on checked flag. For example to register extended meta data on the ph::Site
spec you would create an instance dict with the local name of xmeta-ph-Site
.