componentized/directory

componentized:constants

interface dev

Create custom wasm components that export constant values.

interface factory componentized:constants/factory@0.1.2-dev

Creates components whose exported functions return constant values.

Types

use type component

from componentized:component/types@0.0.0-dev

  • list<u8>

use variant error

from componentized:component/types@0.0.0-dev

  • other: option<string>

use record wit

from componentized:component/wit@0.0.0-dev

variant wit-source

WIT defining the world for the created component to implement.

  • text: string

    WIT text. Packages the world depends on may be defined inline with nested package ns:name { ... } blocks.

  • encoded: component

    A WIT package encoded as wasm, including its dependencies, e.g. from wasm-tools component wit --wasm or wkg build.

  • parsed: wit

    WIT parsed by componentized:component/wit#extract. When extracted from a component, rather than a WIT package, the component's world is implemented by default.

variant overrides

Values replacing those from the WIT. The overrides are a record with an optional field per world export. Interface exports are named by the interface and hold a nested record with a field per function.

  • wave: string

    The record as WAVE source, // line comments are allowed.

Functions

async functioncreate: async func( wit: wit-source, world: option<string>, overrides: option<overrides>, ) -> result<component, error>

Creates a component implementing world from wit.

Every function the world exports must be synchronous, take no parameters and return a value. Values can't reach maps, handles, futures, streams or error contexts, though result types may include them in branches the value doesn't take, e.g. none for an option<own<r>>. Each function's value is a WAVE expression following a @value tag in its doc comment.

  • world: the world to implement, required when the WIT package defines more than one world.
  • overrides: values replacing those from the WIT.

WIT

/// Creates components whose exported functions return constant values.
interface factory {
  use componentized:component/types@0.0.0-dev.{component, error};
  use componentized:component/wit@0.0.0-dev.{wit};

  /// WIT defining the world for the created component to implement.
  variant wit-source {
    /// WIT text. Packages the world depends on may be defined inline with
    /// nested `package ns:name { ... }` blocks.
    text(string),
    /// A WIT package encoded as wasm, including its dependencies, e.g. from
    /// `wasm-tools component wit --wasm` or `wkg build`.
    encoded(component),
    /// WIT parsed by `componentized:component/wit#extract`. When
    /// extracted from a component, rather than a WIT package, the
    /// component's world is implemented by default.
    parsed(wit),
  }

  /// Values replacing those from the WIT. The overrides are a record with
  /// an optional field per world export. Interface exports are named by the
  /// interface and hold a nested record with a field per function.
  variant overrides {
    /// The record as WAVE source, `//` line comments are allowed.
    wave(string),
  }

  /// Creates a component implementing `world` from `wit`.
  ///
  /// Every function the world exports must be synchronous, take no
  /// parameters and return a value. Values can't reach maps, handles,
  /// futures, streams or error contexts, though result types may include
  /// them in branches the value doesn't take, e.g. `none` for an
  /// `option<own<r>>`. Each function's value is a WAVE expression following
  /// a `@value` tag in its doc comment.
  ///
  /// - `world`: the world to implement, required when the WIT package
  ///   defines more than one world.
  /// - `overrides`: values replacing those from the WIT.
  create: async func(wit: wit-source, %world: option<string>, overrides: option<overrides>) -> result<component, error>;
}