pub struct Artifact { /* private fields */ }Expand description
A build output of fetchlet/build: fetchlet.json, the server module
and the client assets.
Artifact::open reads a directory; the manifest names the files
relative to it, and paths that leave it are refused, so a manifest cannot
point the server at other files. include_artifact!
embeds the manifest, the server module and the asset archive in the
binary instead. An asset archive is read and checked when the artifact is
created.
Implementations§
Source§impl Artifact
impl Artifact
Sourcepub fn open(directory: impl Into<PathBuf>) -> Result<Self, ArtifactError>
pub fn open(directory: impl Into<PathBuf>) -> Result<Self, ArtifactError>
Read fetchlet.json in directory.
Sourcepub fn embedded(
manifest: &[u8],
server: impl Into<Cow<'static, str>>,
assets: Option<Bytes>,
) -> Result<Self, ArtifactError>
pub fn embedded( manifest: &[u8], server: impl Into<Cow<'static, str>>, assets: Option<Bytes>, ) -> Result<Self, ArtifactError>
An artifact whose files are in memory, usually through
include_artifact!. assets is required
when the manifest names an asset archive. Embedded artifacts have no
client directory.
Sourcepub fn directory(&self) -> Option<&Path>
pub fn directory(&self) -> Option<&Path>
The artifact directory, for an artifact read with Artifact::open.
Sourcepub fn handler(&self) -> Option<&str>
pub fn handler(&self) -> Option<&str>
The export of the server module that handles Fetch requests, for
AppBuilder::fetch_handler. None for an artifact of functions only,
whose App refuses fetch and serves call.
Sourcepub fn functions(&self) -> Option<&[String]>
pub fn functions(&self) -> Option<&[String]>
The functions the server module exports for App::call, when the
manifest records them.
Sourcepub fn backend(&self) -> Option<&str>
pub fn backend(&self) -> Option<&str>
The engine the server module was built for, such as quickjs.
Sourcepub fn requirements(&self) -> Requirements
pub fn requirements(&self) -> Requirements
What the server module needs from the host that runs it, for
fetchlet::Module::requires: the engine APIs the build left to the
engine and their locales, the engine’s async context, and the Web
APIs and protocol of fetchlet-web. Building an App with them refuses
a host that lacks one before the module runs.
let module = Module::new(artifact.server_source()?).requires(artifact.requirements());For a manifest without needs, they come from nativeRequirements,
intl.locales and asyncContext.
Sourcepub fn server_path(&self) -> Option<PathBuf>
pub fn server_path(&self) -> Option<PathBuf>
The server module’s file, for an artifact read from a directory.
Sourcepub fn server_source(&self) -> Result<String, ArtifactError>
pub fn server_source(&self) -> Result<String, ArtifactError>
The server module’s source, for fetchlet::Module::new.
Sourcepub fn client_directory(&self) -> Option<PathBuf>
pub fn client_directory(&self) -> Option<PathBuf>
The directory of public client assets, when the framework has any and the artifact was read from a directory.
Sourcepub fn asset_archive(&self) -> Option<&Arc<AssetArchive>>
pub fn asset_archive(&self) -> Option<&Arc<AssetArchive>>
The client assets packed by archiveArtifactAssets, when the
manifest names an archive.
Sourcepub fn default_worker_options() -> WorkerOptions
pub fn default_worker_options() -> WorkerOptions
Default WorkerOptions suitable for SSR frameworks: a queue of 8
commands, one instance, and a 64 MiB native worker stack.
Sourcepub fn default_limits() -> Limits
pub fn default_limits() -> Limits
Default Limits for serving an artifact: a 10 s busy_timeout and
a 60 s startup_timeout.
Sourcepub fn default_backend(&self) -> Result<Backend>
pub fn default_backend(&self) -> Result<Backend>
The engine this artifact targets (Backend::for_target), with safe
default QuickJS (4 MiB) and Boa (131,072 value stack slots, 10,000
recursion calls) stack limits for use with Self::default_worker_options.
Sourcepub fn app_builder(&self) -> Result<AppBuilder, ArtifactError>
pub fn app_builder(&self) -> Result<AppBuilder, ArtifactError>
An AppBuilder preconfigured for this artifact: its target backend
with safe stack defaults, Module with artifact.requirements(),
fetch_handler(artifact.handler()), Self::default_limits (plus a
64 MiB heap limit on engines that enforce it), and the current
multi-thread Tokio runtime as host_runtime when available.
Pair with Self::default_worker_options when integrating into a
custom Tower, hyper, axum, or actix-web server.
Sourcepub fn app_builder_with(
&self,
backend: Backend,
) -> Result<AppBuilder, ArtifactError>
pub fn app_builder_with( &self, backend: Backend, ) -> Result<AppBuilder, ArtifactError>
Like Self::app_builder, using an explicit Backend while still
wiring up server_source, requirements, handler, safe default
limits, and host_runtime.