Skip to main content

Crate pylon_functions

Crate pylon_functions 

Source
Expand description

TypeScript function runtime for pylon.

This crate provides the Rust side of the bidirectional protocol between the pylon runtime (Rust) and user-defined TypeScript functions (Bun/Deno).

§Architecture

Client ──► Rust Runtime ──► FunctionRunner ──► Bun Process
               │                                    │
               │  1. Acquire lock (mutations)        │
               │  2. Send {call, fn, args, auth}     │
               │  3. Receive {db, op, ...}      ◄────┘
               │  4. Execute SQL, return result  ────►│
               │  5. Receive {stream, data}     ◄────┘
               │  6. Forward SSE to client            │
               │  7. Receive {return, value}    ◄────┘
               │  8. COMMIT or ROLLBACK               │
               └─────────────────────────────────────-┘

§Function types

  • Query: read-only, uses read pool, concurrent execution
  • Mutation: read+write, transactional, handler IS the transaction
  • Action: external I/O allowed, non-transactional, calls queries/mutations

Modules§

protocol
Bidirectional NDJSON protocol between Rust runtime and TypeScript process.
registry
Function registry — tracks registered TypeScript functions and their metadata.
runner
Function runner — executes TypeScript functions via the bidirectional protocol.
trace
Automatic instrumentation for function executions.