Vectrune documentationAlpha referenceLearning site ↗

Native functions

Builtins dispatched by the Rust server and native execution context.

append

[result =] append <array-path> <value>

Append a resolved value to an array in the execution context.

Runtime: Native / server

Aliases: memory.append

Returns / effects

Mutates the context array; an assignment target receives the updated value. Nested object paths are supported by this builtin.

Errors / edge cases

Missing/non-array targets and invalid nested paths can fail.

Example
append users body

Implementation: src/builtins/builtin/commands.rs

csv.append

csv.append <filename> <record>

Append a record to a CSV file. Relative file resolution uses the app/script path and filesystem candidates.

Runtime: Native / server

Parameters

filename
Filesystem path.
record
Context data or assignment target, as shown in the signature.

Returns / effects

Appends the context object to the target CSV file.

Errors / edge cases

Requires filename and record; invalid data or file writes can fail.

Example
csv.append "users.csv" body

Implementation: src/builtins/builtin/csv.rs

csv.read

rows = csv.read <filename>

Read CSV records. Relative file resolution uses the app/script path and filesystem candidates.

Runtime: Native / server

Parameters

filename
Filesystem path.
result
Context data or assignment target, as shown in the signature.

Returns / effects

Array of objects whose CSV field values are strings. Writes the assigned variable and ___last_exec_result___.

Errors / edge cases

Missing filename is an error. An unreadable file logs a warning and assigns an empty array.

Example
users = csv.read "users.csv"

Implementation: src/builtins/builtin/csv.rs

csv.write

csv.write <filename> <rows>

Replace a CSV file with records. Relative file resolution uses the app/script path and filesystem candidates.

Runtime: Native / server

Parameters

filename
Filesystem path.
rows
Context data or assignment target, as shown in the signature.

Returns / effects

Writes a header from the first object and rows from the supplied context array.

Errors / edge cases

Missing/non-array variable and write failures are errors. Values are written through their string representation path; do not assume JSON numeric values are preserved.

Example
csv.write "users.csv" users

Implementation: src/builtins/builtin/csv.rs

datasource

[result =] datasource <action> <Schema> <operation arguments...>

Dispatch a schema-based database operation through a configured native MySQL or PostgreSQL source.

Runtime: Native / server

Returns / effects

Operation-dependent result or side effect. Supported actions: create_table, fetch_all, fetch, insert, update, delete.

Errors / edge cases

Unknown source, missing connection/type, unsupported connection type, and database/query failures.

Example
datasource create_table User in Users
datasource fetch_all User from Users into data

Implementation: src/builtins/builtin/data_source.rs

db

result = db <source> <packet>

Execute one Rune DB operation packet against a named datasource.

Runtime: Native Rune / Rune-Web action I/O

Parameters

source
Named rune-db provider for db, or vect-event provider for events.
packet
Context variable containing the operation object. See knowledge/runtime/storage.md.

Returns / effects

Operation result or atomic commit receipt. Pure expressions remain synchronous; browser top-level actions resume after completion.

Errors / edge cases

Invalid packets, revision conflicts and persistence failures reject the operation. Batches roll back together.

Example
packet = { op: "get", collection: "notes", key: "hello" }
record = db main packet

Implementation: src/storage/mod.rs · src/storage/provider.rs · src/builtins.rs · runtime/rune-web/src/datasource.ts

delete

delete <path>

Delete a top-level context variable or nested object property.

Runtime: Native / server

Returns / effects

Mutates the current context. Missing targets are ignored.

Errors / edge cases

Missing path is a builtin error.

Example
delete state.players.[id]

Implementation: src/builtins/builtin/context_ops.rs

events

result = events <source> <packet>

Append or read durable events through a named vect-event provider.

Runtime: Native Rune / Rune-Web action I/O

Parameters

source
Named rune-db provider for db, or vect-event provider for events.
packet
Context variable containing the operation object. See knowledge/runtime/storage.md.

Returns / effects

Operation result or atomic commit receipt. Pure expressions remain synchronous; browser top-level actions resume after completion.

Errors / edge cases

Invalid packets, revision conflicts and persistence failures reject the operation. Batches roll back together.

Example
packet = { op: "read", stream: "orders", after: "0", limit: 20 }
page = events activity packet

Implementation: src/storage/mod.rs · src/storage/provider.rs · src/builtins.rs · runtime/rune-web/src/datasource.ts

fetch

result = fetch <url|name> [options <binding>] [catch <handler>]

Perform an outbound HTTP GET and return {status, body}.

Runtime: Native / server

Parameters

url
http(s) URL literal, or a name (e.g. an @Values entry) holding one.
options
Optional binding holding headers, timeout_ms, max_body_bytes, or redirect. Custom header requests reject redirects.
catch
Optional: func/action called with the error ($1 / payload {status, message}).

Returns / effects

Writes the response (fetch: {status, body}; fetch-json: parsed JSON) to the assignment target and ___last_exec_result___.

Errors / edge cases

GET only; http/https only; Default 10s timeout and 1 MiB cap, configurable per request. Native REST: 502 for upstream non-2xx/bad JSON/network errors, 504 on timeout, unless a catch handler is given. Rune-Web: failures call the catch action; browser CORS rules apply.

Example
response = fetch weather_url

Implementation: src/builtins/builtin/http_fetch.rs · runtime/rune-web/src/builtins/fetch.ts

fetch-json

result = fetch-json <url|name> [options <binding>] [catch <handler>]

Perform an outbound HTTP GET and parse the body as JSON.

Runtime: Native / server

Parameters

url
http(s) URL literal, or a name (e.g. an @Values entry) holding one.
options
Optional binding holding headers, timeout_ms, max_body_bytes, or redirect. Custom header requests reject redirects.
catch
Optional: func/action called with the error ($1 / payload {status, message}).

Returns / effects

Writes the response (fetch: {status, body}; fetch-json: parsed JSON) to the assignment target and ___last_exec_result___.

Errors / edge cases

GET only; http/https only; Default 10s timeout and 1 MiB cap, configurable per request. Native REST: 502 for upstream non-2xx/bad JSON/network errors, 504 on timeout, unless a catch handler is given. Background jobs fail on errors and accept only assigned calls with dotted URL and optional options paths, without callbacks. Rune-Web: failures call the catch action; browser CORS rules apply.

Example
weather = fetch-json weather_url

Implementation: src/builtins/builtin/http_fetch.rs · runtime/rune-web/src/builtins/fetch.ts

func

func <name> <step>; <step>; ...

Register a sequence of semicolon-separated native steps in the current context.

Runtime: Native / server

Returns / effects

Stores steps under func:<name>. Invocations expose positional arguments as $1, $2, ... and copy non-positional context values back to the caller.

Errors / edge cases

Missing function name is a builtin error; directly surfaced builtin failures inside a function propagate to its caller, including failures from arithmetic command operands.

Example
func greet log "hello"; respond 200 "OK"

Implementation: src/builtins/builtin/function.rs

is-set

result = is-set <path>

Check whether a variable or resolved path exists in the execution context.

Runtime: Native / server

Returns / effects

True when the variable or path exists, including when its value is negative, zero, or null. False when it cannot be resolved.

Errors / edge cases

Omitting the path argument is a builtin error.

Example
body = { response: -1, feedback: null }
present = is-set body.response
feedback_present = is-set body.feedback
missing = is-set body.extra

Implementation: src/builtins/builtin/context_ops.rs

json.read

result = json.read <filename>

Read a JSON file and parse its contents.

Runtime: Native / server

Returns / effects

Parsed JSON is written to the assignment target and ___last_exec_result___.

Errors / edge cases

Requires a filename and assignment target. File-read and JSON-parse failures return builtin errors.

Example
settings = json.read "settings.json"

Implementation: src/builtins/builtin/json.rs

list.slice

result = list.slice <array> <start> [end]

Return a subarray slice from start index to optional end index.

Runtime: Native / server

Returns / effects

New sliced array.

Example
top = list.slice ranked 0 10

Implementation: src/builtins/builtin/str_list.rs

list.sort-by

result = list.sort-by <array> <field> [asc|desc]

Return a new array sorted by a numeric or string object field.

Runtime: Native / server

Returns / effects

New sorted array; ascending by default, or descending when "desc" is passed.

Example
ranked = list.sort-by hits "score" "desc"

Implementation: src/builtins/builtin/str_list.rs

load-rune

result = load-rune <path> [as xml]

Load a Rune file or directory, resolving its top-level imports before parsing.

Runtime: Native / server

Returns / effects

Document data in JSON form by default, or an XML string when as xml is supplied.

Errors / edge cases

Requires a path; loading/parsing failure is an error. The explicit conversion form supports xml.

Example
document = load-rune "shared.rune"

Implementation: src/builtins.rs

log

log <message...>

Expand {expression} placeholders using the current execution context and write the message to the logger.

Runtime: Native / server

Parameters

message
One or more message tokens; quoted text may contain spaces.

Returns / effects

Stores the expanded message in ___last_exec_result___. Unknown placeholders remain unchanged.

Example
log "Fetching user {id}"

Implementation: src/builtins/builtin/logger.rs

memory.cas

[swapped =] memory.cas <key> <expected> <new> [--key-from-context] [--ttl <seconds>]

Atomically replace a memory entry only if its current value equals expected.

Runtime: Native / server

Returns / effects

Assigns true to the target and ___last_exec_result___ when the swap succeeds, or false when the current value does not match expected.

Errors / edge cases

Missing arguments, unknown/extra arguments, invalid --ttl, or an invalid context key is a builtin error.

Example
swapped = memory.cas sid expected next --key-from-context
created = memory.cas sid null initial --key-from-context --ttl 300

Implementation: src/builtins/builtin/memory.rs

memory.clear

memory.clear

Remove all keys from the process memory backend.

Runtime: Native / server

Aliases: clear-memory

Returns / effects

Clears the shared backend, not only the current request context.

Errors / edge cases

Unexpected arguments return a builtin error.

Example
memory.clear

Implementation: src/builtins/builtin/memory.rs

memory.del

memory.del <key>
memory.del <path> --key-from-context

Delete a key from the process memory backend.

Runtime: Native / server

Aliases: del-memory

Returns / effects

Removes the key; no assigned result.

Errors / edge cases

Missing key, unknown/extra arguments, or a context key that does not resolve to a nonempty string is a builtin error.

Example
memory.del "user"
memory.del path.params.id --key-from-context

Implementation: src/builtins/builtin/memory.rs

memory.get

result = memory.get <key>
result = memory.get <path> --key-from-context

Read a value from the process memory backend.

Runtime: Native / server

Aliases: get-memory

Returns / effects

Assigns the stored JSON value and ___last_exec_result___ when found. A missing or expired key logs a warning and leaves the context unchanged; it does not assign null.

Errors / edge cases

Missing key, unknown/extra arguments, or a context key that does not resolve to a nonempty string is a builtin error.

Example
user = memory.get "user"
stored = memory.get path.params.id --key-from-context

Implementation: src/builtins/builtin/memory.rs

memory.push

[result =] memory.push <key> <value> [--key-from-context] [--ttl <seconds>]

Atomically append a value to a list in the process memory backend.

Runtime: Native / server

Returns / effects

Creates a one-element list if the key is missing or expired, otherwise appends under the backend write lock and assigns the updated list to the target and ___last_exec_result___.

Errors / edge cases

Missing arguments, unknown/extra arguments, invalid --ttl, an invalid context key, or an existing non-list value at the key is a builtin error.

Example
items = memory.push sid item --key-from-context
items = memory.push "events" payload --ttl 600

Implementation: src/builtins/builtin/memory.rs

memory.set

memory.set <key> [value] [--ttl <seconds>]
memory.set <path> <value> --key-from-context [--ttl <seconds>]

Store a value in the process memory backend.

Runtime: Native / server

Aliases: set-memory

Returns / effects

Uses an exact context-variable lookup for value; otherwise stores literal text. If omitted, value uses the key token.

Errors / edge cases

Missing key, an invalid --ttl duration, unknown/extra arguments, or a context key that does not resolve to a nonempty string is a builtin error.

Example
memory.set "user" body
memory.set path.params.id record --key-from-context --ttl 300

Implementation: src/builtins/builtin/memory.rs

now

result = now [format]

Read the current UTC time.

Runtime: Native / server

Returns / effects

Default: RFC 3339 string. millis: Unix milliseconds. unix or seconds: Unix seconds.

Example
timestamp = now millis

Implementation: src/builtins/builtin/coercion.rs

parse-json

[result =] parse-json [source]

Parse a JSON string stored in the request context.

Runtime: Native / server

Parameters

source
Context variable containing a JSON string; defaults to body.

Returns / effects

Writes parsed JSON to the assignment target, or body when unassigned, and ___last_exec_result___.

Errors / edge cases

Malformed JSON raises a builtin error (HTTP 500 in a native REST request). A missing or non-string source leaves the context unchanged in legacy Rune execution, but fails a background job.

Example
payload = parse-json body

Implementation: src/builtins/builtin/parse_json.rs

respond

respond [status] [value...]

Finish the current request with an HTTP status and response body.

Runtime: Native / server

Parameters

status
HTTP status integer; defaults to 200 if absent or not parseable.
value
A context variable name, an unquoted object expression after an explicit status, or literal text. Defaults to OK.

Returns / effects

HTTP response. Context objects and unquoted object expressions are serialized as JSON text. The native REST handler uses a text/plain response body; generated OpenAPI documents detected status codes with a string response schema.

Example
respond 200 "Echoed: {pretty data}"

Implementation: src/builtins/builtin/respond.rs

str.contains

result = str.contains <haystack> <needle>

Check whether a string contains a substring.

Runtime: Native / server

Returns / effects

Boolean true when needle appears in haystack; otherwise false.

Example
matched = str.contains summary "rest"

Implementation: src/builtins/builtin/str_list.rs

str.join

result = str.join <array> [separator]

Join array elements into a single string with an optional separator.

Runtime: Native / server

Returns / effects

Joined string; non-array inputs return an empty string.

Example
slug = str.join words "-"

Implementation: src/builtins/builtin/str_list.rs

str.lower

result = str.lower <value>

Convert a string value to lowercase.

Runtime: Native / server

Returns / effects

Lowercased UTF-8 string.

Example
normalized = str.lower query

Implementation: src/builtins/builtin/str_list.rs

str.split

result = str.split <text> [separator]

Split a string into an array on whitespace or an explicit separator.

Runtime: Native / server

Returns / effects

Array of string parts.

Example
terms = str.split query

Implementation: src/builtins/builtin/str_list.rs

str.trim

result = str.trim <value>

Strip leading and trailing whitespace from a string.

Runtime: Native / server

Returns / effects

Trimmed string.

Example
clean = str.trim raw_input

Implementation: src/builtins/builtin/str_list.rs

summarize

result = summarize <records> by <group-path> [<metric> <value-path>]

Group records into an ordered, non-mutating report.

Runtime: Native / server

Parameters

metric
sum, avg, min, max, median, distinct, first, or last. Omit for counts.

Returns / effects

Array of groups in first-occurrence order, with counts and the requested metric. Missing group fields join the null group.

Errors / edge cases

Invalid syntax, non-array input, unsupported metrics, invalid paths, and non-numeric metric values can fail.

Example
report = summarize sales by region sum amount

Implementation: src/builtins/builtin/summarize.rs

to-bool

result = to-bool [value]

Convert a context value to a boolean.

Runtime: Native / server

Returns / effects

Strings are true only for case-insensitive true or exactly 1. Numbers are true when nonzero; null is false; objects and arrays are true. No argument is false.

Example
enabled = to-bool input

Implementation: src/builtins/builtin/coercion.rs

to-json

result = to-json <value>

Serialize a context value, object, or array to a compact JSON string.

Runtime: Native / server

Returns / effects

Compact JSON string representation of the resolved value.

Example
encoded = to-json payload

Implementation: src/builtins/builtin/str_list.rs

to-number

result = to-number <value>

Convert a resolved number, numeric string, or boolean to a number.

Runtime: Native / server

Returns / effects

A JSON number, or null for an unsupported/unparseable value. Booleans map to 1 and 0.

Example
value = to-number id

Implementation: src/builtins/builtin/coercion.rs

to-string

result = to-string [value]

Convert a context value or literal token to a string.

Runtime: Native / server

Returns / effects

Existing strings are preserved; other JSON values are serialized. No argument produces an empty string.

Errors / edge cases

In background jobs, exactly one existing dotted source path is required; a missing path fails the job.

Example
text = to-string body

Implementation: src/builtins/builtin/coercion.rs

uuid.v4

result = uuid.v4

Generate a random version 4 UUID.

Runtime: Native / server

Aliases: uuid

Returns / effects

Hyphenated UUID string.

Example
id = uuid.v4

Implementation: src/builtins/builtin/coercion.rs

validate

validate <value> #<Schema>
validate <left> <operator> <right> "message"

Validate required scalar fields against a named schema, or check a comparison.

Runtime: Native / server

Parameters

value
Context variable to validate.
Schema
An @Schema name; supported scalar field types are string, number, bool.

Returns / effects

Schema form stores the validated value in ___last_exec_result___. Validation failures finish the request with HTTP 400.

Errors / edge cases

Missing field, type mismatch, or unknown schema/value. Additional properties are accepted; nested/optional schema validation is not implemented by this path.

Example
parse-json
validate body #Greeting

Implementation: src/builtins/builtin/validate.rs

verify

verify <source> as <Schema> into <target>

Parse JSON and validate required fields against a named schema.

Runtime: Native / server

Parameters

source
Dotted context path containing a JSON string.
Schema
Named @Schema with scalar, nested schema or array fields.
target
Writable simple identifier.

Returns / effects

Writes the parsed object to the target on success; preserves the source and ___last_exec_result___ unless either is the target.

Errors / edge cases

Invalid JSON or data responds 400. Invalid command or schema, missing or non-string source, and read-only targets fail execution. No target is written on failure.

Example
verify body as Order into order

Implementation: src/builtins/builtin/verify.rs · tests/verify_builtin.rs

ws.broadcast

ws.broadcast <path> <message...>

Broadcast a message to connections registered on a WebSocket path.

Runtime: Native / server

Aliases: broadcast-websocket

Returns / effects

Queues the message for connections on the supplied path.

Errors / edge cases

Requires a path and message.

Example
ws.broadcast /chat body

Implementation: src/builtins/builtin/ws.rs

ws.id

id = ws.id

Read the identifier of the current WebSocket connection.

Runtime: Native / server

Returns / effects

Connection ID string, or null outside a connection context.

Example
id = ws.id

Implementation: src/builtins/builtin/ws.rs

ws.send

ws.send <path> <connection-id> <message...>

Send a message to one WebSocket connection.

Runtime: Native / server

Returns / effects

Queues a message in the process-local connection registry.

Errors / edge cases

Requires a path, connection ID, and message.

Example
ws.send /chat id body

Implementation: src/builtins/builtin/ws.rs