Alternera. PluginWasmFramework. Upload
(alternera_plugin_wasm_framework v0.9.0)
Copy Markdown
View Source
Takes a compiled module a user uploads into a step: checks it, compiles
it and stores it (Plugin.Provisional.Files), so a broken module is
refused in the editor, never on the first request.
The checks, in order, each refused with a text of its own (the runtime's own reasons go to the log only):
- uploads are on for this node (the plugin's
upload_settings/0), and a user is signed in to store the file as; - the file is at most
max_bytes; - it is a well-formed core module (
ModuleFile), not a component; - it imports only
alternera.host_call,alternera.body_readand functions of WASI preview 1, which the runtime serves with nothing granted; anything else is refused, never stubbed; - it has no start function: a start function runs while the module
is instantiated, before any time limit applies, and one that loops
keeps a processor busy for good (
_initializeis the way to initialise, and runs within the call's time); - it defines one memory, not shared and not 64-bit, whose minimum is
within the node's ceiling (
MemoryLimit.ceiling_mib/0); - it exports
memory,alternera_abi,alternera_alloc,alternera_runandalternera_check; - its
alternera.usessection is well formed (Uses); - it fits the tenant's share of storage (
max_tenant_bytes), read before it compiles so a tenant at its quota costs no compile, and checked again as it is stored; a file that does not fit first has the tenant's unreferenced files removed (Files.reclaim/1) and is measured again; - the tenant has not compiled more than
per_minutenew modules on this node in the last minute (a file the tenant stored before is taken as it is: it neither compiles here nor counts, and a step compiles it when it first runs on a node that lacks it); - it compiles and answers interface version 0, within 5 s, one
compile at a time on the node (
UploadedModules); - it is stored (
Files.put/5).
The rate and the cache are per node.
An import that carries a module (Plugin.Provisional.Files) runs the
same: check_file/2 (1 to 8 without a user) for its preview,
accept/5 as it lands.
Summary
Types
An accepted module, as the step editor shows it.
The guards an uploading plugin sets: whether uploads are on, the largest file, new modules a tenant may compile a minute, and the most a tenant's files may hold together.
Functions
Checks, compiles and stores bytes, uploaded as name by user_id
for tenant_id into a step of lang.
The checks on the file's outline (3 to 7 in the moduledoc), without compiling it: its outline, or the first refusal.
The checks on bytes that cost nothing, for an import's preview: the
switch, the size, the outline and the alternera.uses section (1 to 8
above, without the user). :ok or the refusal accept/5 would give.
A byte count as people read it (176 KB, 8 MB).
Types
@type accepted() :: %{ digest: String.t(), name: String.t(), size: non_neg_integer(), uses: Alternera.PluginWasmFramework.Uses.t(), new?: boolean() }
An accepted module, as the step editor shows it.
@type settings() :: %{ enabled?: boolean(), max_bytes: pos_integer(), per_minute: pos_integer(), max_tenant_bytes: pos_integer() }
The guards an uploading plugin sets: whether uploads are on, the largest file, new modules a tenant may compile a minute, and the most a tenant's files may hold together.
Functions
@spec accept( Alternera.PluginWasmFramework.Language.t(), String.t(), String.t() | nil, String.t(), binary() ) :: {:ok, accepted()} | {:error, String.t()}
Checks, compiles and stores bytes, uploaded as name by user_id
for tenant_id into a step of lang.
@spec check(binary()) :: {:ok, Alternera.PluginWasmFramework.ModuleFile.t()} | {:error, String.t()}
The checks on the file's outline (3 to 7 in the moduledoc), without compiling it: its outline, or the first refusal.
@spec check_file(Alternera.PluginWasmFramework.Language.t(), binary()) :: :ok | {:error, String.t()}
The checks on bytes that cost nothing, for an import's preview: the
switch, the size, the outline and the alternera.uses section (1 to 8
above, without the user). :ok or the refusal accept/5 would give.
@spec format_bytes(non_neg_integer()) :: String.t()
A byte count as people read it (176 KB, 8 MB).