veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

mobile

lib/mobile.vk

lib/mobile.vk Pure-Veko homoiconic mobile bridge specification (BridgeSpec), typed model/endpoint builders, quote [...] bridge dialect parser (parse-bridge-quote), .secret wire redactor (redact-model), and safe C-ABI / JNI / Swift JSON RPC dispatcher (dispatch-json). Zero capabilities required.

FieldDef struct
signature
FieldDef = struct { name str, typ str, default_lit str = ..., is_secret bool = ... }

Field descriptor for a mobile bridge model, state, or endpoint parameter list.

ModelDef struct
signature
ModelDef = struct { name str, fields block[FieldDef] }

Data model or root AppState schema shared across Veko and Swift / Kotlin bindings.

signature
EndpointDef = struct { kind enum, name str, params block[FieldDef], ret_type str }

Typed RPC endpoint descriptor (kind in .command or .query).

BridgeSpec struct
signature
BridgeSpec = struct { name str, pkg_id str = ..., state_model ModelDef, models block[ModelDef] = ..., endpoints block[EndpointDef] = ... }

Complete mobile core bridge specification driving Swift/Kotlin binding generation and runtime dispatch.

signature
field = fn [name str, typ str] FieldDef

Creates a non-secret FieldDef without a default value.

signature
field-default = fn [name str, typ str, def_lit str] FieldDef

Creates a non-secret FieldDef with default literal def_lit.

signature
secret-field = fn [name str, typ str] FieldDef

Creates a .secret-protected FieldDef (is_secret = true, automatically redacted across FFI/JSON).

signature
model = fn [name str, fields block[FieldDef]] ModelDef

Creates a ModelDef schema from name and fields.

signature
command = fn [name str, params block[FieldDef], ret_type str] EndpointDef

Creates a mutating .command EndpointDef.

signature
query = fn [name str, params block[FieldDef], ret_type str] EndpointDef

Creates a read-only .query EndpointDef.

signature
bridge-spec = fn [name str, pkg_id str, state_model ModelDef, models block[ModelDef], endpoints block[EndpointDef]] BridgeSpec

Assembles a complete BridgeSpec.

signature
parse-bridge-quote = fn [name str, qblock block] BridgeSpec

Parses a homoiconic quote [...] mobile bridge specification block into a typed BridgeSpec.

Executable Example
veko
use [mob = mobile]
spec = mob/parse-bridge-quote 'FieldSyncCore' (quote [
  package 'dev.veko.fieldsync'
  model VaultSession [
    field user_id str
    secret access_token str
  ]
  state AppState [
    field online bool true
  ]
  command add-item [title str] bool
  query list-pending [] block
])
if spec.pkg_id != 'dev.veko.fieldsync' or (len spec.models) != 1 or (not spec.models[0].fields[1].is_secret) or (len spec.endpoints) != 2 [
  err 'parse-bridge-quote'
] else [ .ok ]
signature
redact-model = fn [val any, spec BridgeSpec] any

Walks maps, structs, and blocks recursively, replacing any field marked is_secret == true in spec (as well as any runtime .secret-tainted value) with '<secret>' prior to wire serialization.

signature
redact-secrets = fn [val any, spec BridgeSpec] any

Alias for redact-model.

signature
dispatch-json = fn [handlers map, spec BridgeSpec, op str, payload_json str] str

Decodes payload_json, invokes op in handlers (map of op_name -> fn [map] any), catches Veko err values as {"ok":false,"error":"..."}, redacts .secret fields per spec, and returns {"ok":true,"data":...}.

Executable Example
veko
use [mob = mobile]
spec = mob/parse-bridge-quote 'Core' (quote [
  model Session [ field uid str  secret token str ]
  state AppState [ field ready bool true ]
  query current-session [] Session
])
handlers = {
  'current-session' = fn [req map] any [ { uid = 'u1', token = 'live_secret_xyz' } ]
}
resp = mob/dispatch-json handlers spec 'current-session' '{}'
if (not (str/contains? resp '"ok":true')) or (not (str/contains? resp '"<secret>"')) or (str/contains? resp 'live_secret_xyz') [
  err 'dispatch-json'
] else [ .ok ]