m15o.net/wombat/lib/wom

NAME

wom - kernel

SYNOPSIS

req(v, p, d, ns)
mount(p, h, ns)
err(m)

DESCRIPTION

The kernel is the first file a host runs. It defines the calls below.

Req and mount take an optional namespace, ns: an object that maps names to path, such as:

{ 'proc/': '/srv/proc/p1/' }

If a name in ns matches the start of p, it is replaced by its path, once, before the call goes on: with that namespace, proc/status means /srv/proc/p1/status.

A name ending in / matches everything under it, and any other name matches itself only. When several match, the longest wins. The result must start with /.

req

Req sends a 6b request: a verb v, a path p, and, for a put, a body d. It returns the text of the response.

If req returns, the request succeeded, whatever the text. An empty string is the usual response to a put or a del.

If the response is an error, req throws: the message is the reason.

A get also records the file as a dependency of the computation in progress if there is one. When the file changes, that computation runs again.

mount

Mount makes the handler h serve the path p. A path ending in / also serves everything under it, and when several mounts match a request, the longest path wins. Mounting a path that is already served fails with 'busy'. Mount returns an object whose dis function unmounts.

The handler is called as h(v, p, d, n): the verb, the path relative to the mount, the body, and n. What it returns is the text of the response. The last argument, n, passes the request on to whatever would have answered without this mount, and returns its response. Called as n(), it passes the request unchanged; as n(v, p, d), it makes another request, with an absolute path, and any argument left out is taken from the original request.

err

Err throws an error whose message is the reason m. A handler calls it to refuse a request: err('not allowed')

REF

intro(bin)